博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
设置datagridview中button按钮的背景颜色
阅读量:6949 次
发布时间:2019-06-27

本文共 872 字,大约阅读时间需要 2 分钟。

问题: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);      }}

效果:

 

转载地址:http://uyuil.baihongyu.com/

你可能感兴趣的文章
在Hadoop上运行基于RMM中文分词算法的MapReduce程序
查看>>
mysql做主从分离后插入更新过慢
查看>>
我的友情链接
查看>>
使用java7的try-resource-with语法用httpclient抓取网页并用jsoup获取网页对象
查看>>
Linux查看进程
查看>>
Android项目:通过ant重新打包proguard混淆器jar文件
查看>>
初识WEB:输入URL之后的故事
查看>>
[每日一题] 11gOCP 1z0-052 :2013-09-16 shared server mode........................................B21...
查看>>
memcached 快速入门
查看>>
__flash__removeCallback 未定义错误
查看>>
线程安全
查看>>
本地管理表空间(LMT)
查看>>
Go 标准库介绍五: io
查看>>
使用Nginx实现负载均衡
查看>>
Java程序员从笨鸟到菜鸟之(五十)细谈Hibernate(一)hibernate基本概念和体系结构...
查看>>
Ubuntu“ System Program Problem Detected”问题
查看>>
JavaScript—call, apply, bind 函数(20)
查看>>
又发现昆仑通态的一个BUG
查看>>
Windbg记事本
查看>>
Nutch数据集的目录具体内容
查看>>