zoukankan      html  css  js  c++  java
  • 设置datagridview中button按钮的背景颜色

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

    回答:可以在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);
          }
    }

    效果:

  • 相关阅读:
    jquery animate() stop() finish() 方法使用
    ant 相关命令
    ant 安装 网址
    邮件
    webdriver until
    python HTML报告
    登录
    yun
    centos7搭建smb服务
    爬取图片
  • 原文地址:https://www.cnblogs.com/guwei4037/p/5642778.html
Copyright © 2011-2022 走看看