无法在DataGridView的单元格使用Color.FromArgb背景色

问题描述:

我通过的DataGridView 控制着循环动态添加行。我设置基于以下逻辑每个单元的背景色属性:

I am looping through a DataGridView control and adding rows dynamically. I am setting the BackColor property of each cell based on the following logic:

if (bidVolume != null)
{
    this.Rows[this.RowCount - 1].Cells[1].Style.BackColor = Color.Green;
}
else
{
    this.Rows[this.RowCount - 1].Cells[1].Style.BackColor = Color.FromArgb(150, Color.Green);
}

这是造成问题,颜色设置不正确视觉上,当调整大小的的DataGridView 它看起来是这样的:

This is causing problems, the color is not properly set visually and when re-sizing the DataGridView it looks like this:

当我不使用 Col​​or.FromArgb 键,只需使用 Col​​or.Red 为例,此时一切正常精..

When I don't use Color.FromArgb and just use Color.Red for example, then everything works fine ..

是否可以设置一个单元格背景色使用 Col​​or.FromArgb

Is it possible to set a cell BackColor using Color.FromArgb ?

感谢

您无法使用 Col​​or.FromArgb ,因为的DataGridView 将不接受透明色。这可能是由于以下事实的细胞和DataGridView的不透明(默认)引起的。你正在寻找的是probalby this;您可能要设置背景色来白色和绿色的颜色。

You cannot use Color.FromArgb, because DataGridView won't accept transparent colors. This is probably caused by the fact that the cells and DataGridView are not transparent (by default). What you are looking for is probalby this; you may want to set BackColor to color between White and Green.

如果我错了,这是不是你想要请说明您需要在单元格中的Alpha通道是什么。

If I am mistaken and this is not what you want please explain your need for alpha channel in the cell.