【问题标题】:DataGridViewImageColumn background is blackDataGridViewImageColumn 背景为黑色
【发布时间】:2020-06-15 23:33:55
【问题描述】:

我有一个表格,其中一列是图像类型。当使用“ImageLayout”属性作为“Stretch”时,背景是黑色的。如何将其更改为白色?

我正在使用转换为 bipmap 的“SystemIcons”图标集。

 private Bitmap GetIcone()
 {
    return SystemIcons.Warning.ToBitmap();
 }

并以这种方式插入:

row.Cells["ColStatusIcone"].Value = GetIcone(status.icone);

【问题讨论】:

    标签: c# datagridview bitmap background datagridviewimagecolumn


    【解决方案1】:

    编辑:如果您只想将背景颜色更改为白色图像单元格:

         dataGridView1.CellFormatting += (x, y) =>
             {
                 if (y.DesiredType == typeof(Image)){
                    y.CellStyle.BackColor = Color.White;
               } 
             };
    

    您可以尝试在 CellFormattingEvent 上将图像列的颜色更改为白色。试试这个:

     dataGridView1.CellFormatting += (x, y) =>
             {
                 if (y.ColumnIndex != 1) //your image cell index
                 {
                     return;
                 }
                 y.CellStyle.BackColor = Color.White;
             };
    

    【讨论】:

    • 我做了测试,它可以绘制任何文本单元格,除了图像单元格
    • 对不起。请将 if 条件更改为“ if (y.DesiredType == typeof(Image))”。
    猜你喜欢
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    • 2011-11-28
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多