日期:2014-05-17  浏览次数:20763 次

在winfrom程序里面 DataGridViewButtonColumn列 按键的背景色怎样修改
如题
如何修改datagridview内定义为DataGridViewButtonColumn列的按钮的背景色 不是Cell的背景色

------解决方案--------------------
C# code

  private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                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);
            }
        }