DataGridViewButtonColumn()在datagridview中创建按钮列,如何设置按钮的背景颜色(不是单元格的背景颜色)。

解决方案 »

  1.   

    Button的颜色需要重绘才能改变。
      

  2.   

    还有问想一下不同的button可以设置不同的背景颜色吗
      

  3.   

    可以在dataGridView1_CellPainting事件里面处理。
    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
            {
                if (e.ColumnIndex == 0)//索引0
                {
                    e.Handled = true;                using (SolidBrush brush = new SolidBrush(Color.Red))
                    {
                        e.Graphics.FillRectangle(brush, e.CellBounds);
                    }
                    ControlPaint.DrawBorder(e.Graphics, e.CellBounds, Color.Yellow, ButtonBorderStyle.Outset);
                }
                if (e.ColumnIndex == 1)//索引1
                {
                    e.Handled = true;                using (SolidBrush brush = new SolidBrush(Color.BlueViolet))
                    {
                        e.Graphics.FillRectangle(brush, e.CellBounds);
                    }
                    ControlPaint.DrawBorder(e.Graphics, e.CellBounds, Color.Yellow, ButtonBorderStyle.Outset);
                }
            }
    效果:
      

  4.   

    想问一下这个button有透明度吗