博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【WinForm】改变DataGridView的按钮的文字颜色
阅读量:7192 次
发布时间:2019-06-29

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

using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; ///  ///  public class MyDataGridViewButtonCell :     DataGridViewButtonCell {
// By default, not set the color ot text. private bool isSetColor = false; private Color textColor; /// /// public Color TextColor {
get {
return textColor; } set {
isSetColor = true; textColor = value; } } /// /// /// /// /// /// /// /// /// /// /// /// /// /// protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
// The button cell is disabled, so paint the border, // background, and disabled button for the cell. if (isSetColor) {
// Calculate the area in which to draw the button. Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = this.BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; // Draw the disabled button. ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Default); // Draw the disabled button text. if (this.FormattedValue is String) {
TextRenderer.DrawText(graphics, (string)this.FormattedValue, this.DataGridView.Font, buttonArea, this.textColor); } } else {
// The button cell is enabled, so let the base class // handle the painting. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } } }

参照链接:

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

你可能感兴趣的文章
【转】iOS lame编译 arm64 armv7s armv7 x86_64 i386指令集
查看>>
LeetCode-二叉树的最大深度
查看>>
Linux内核剖析(五)Linux内核的构建过程
查看>>
19、生鲜电商平台-安全设计与架构
查看>>
Django_06_项目完成
查看>>
寻找子字符串int find_substr(char *s1, char *s2)
查看>>
Manifest.xml中不要出现重复的uses-permission声明
查看>>
UFS文件系统简明学习笔记
查看>>
详解Redis 的持久化机制--RDB和AOF
查看>>
就算神游 之四:富士山和富士游乐园 9
查看>>
linux 学习 12 服务管理
查看>>
maven全局配置文件settings.xml详解
查看>>
模型图纸数据库设计
查看>>
Two classes have the same XML type name 排错【转】
查看>>
linux笔记:linux常用命令-关机重启命令
查看>>
Configuring and troubleshooting a Schema Provider
查看>>
Windows环境安装MySQL数据库
查看>>
javascript函数以及作用域简介
查看>>
Windows Phone 编程中页面间传值方法 - [WP开发]
查看>>
apollo实现c#与android消息推送(四)
查看>>