-2
我有如下一个DataGridView:如何使单元格datagridview的透明alpha颜色?
我想作一个细胞的datagridview的背景颜色约20%,50%,...透明的(不完全透明),那里是一个背景中的颜色(即黑色,紫色,灰色,...)?
我已经尝试了许多方法,但我不能做到这一点:
private void CustomerDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
// Black 20%
if (e.ColumnIndex == 1)
{
SetCellsTransparent(e.RowIndex, Color.Black, 0.2);
}
// Purple 50%
if (e.ColumnIndex == 2)
{
SetCellsTransparent(e.RowIndex, Color.Purple, 0.5);
}
// Gray 100%
if (e.ColumnIndex == 3)
{
SetCellsTransparent(e.RowIndex, Color.Gray, 1);
}
}
catch (Exception) { }
}
public void SetCellsTransparent(int rowIdx, Color color, double transparency)
{
//Color color = ColorTranslator.FromHtml("#000000");
//Color color = Color.Red;
//this.Rows[rowIdx].Cells[0].Style.BackColor = color;
//this.Rows[rowIdx].Cells[0].Style.BackColor = Color.FromArgb(50, color);
var whiteness = 255 - Convert.ToInt32(transparency * 255);
this.Rows[rowIdx].Cells[0].Style.BackColor = Color.FromArgb(255, whiteness, whiteness); //Red
this.ClearSelection();
}
这些任何提示将是很大的帮助。提前致谢。
这是一个WPF或基本形式,你正在使用? – Kyon
对不起,没有清楚解释。这是一个基本的窗体,窗体应用程序。 – MinhKiyo
你试过Color.FromArgb(白度,颜色)吗? https://msdn.microsoft.com/pt-br/library/1hstcth9(v=vs.110).aspx – Magnetron