我有一个表格,其中一列是图像类型。当使用 "ImageLayout "属性为 "Stretch "时,背景是黑色的。如何将其改为白色?
我使用的是 "SystemIcons "图标集转换为bipmap。
private Bitmap GetIcone()
{
return SystemIcons.Warning.ToBitmap();
}
并这样插入。
row.Cells["ColStatusIcone"].Value = GetIcone(status.icone);
编辑:如果你想把背景颜色改成白色,只有图像单元。
dataGridView1.CellFormatting += (x, y) =>
{
if (y.DesiredType == typeof(Image)){
y.CellStyle.BackColor = Color.White;
}
};
你可以尝试将你的图像列的颜色改为白色。单元格格式化事件. 试试这个
dataGridView1.CellFormatting += (x, y) =>
{
if (y.ColumnIndex != 1) //your image cell index
{
return;
}
y.CellStyle.BackColor = Color.White;
};