Winform重画ComboBox背景色
//返回hWnd参数所指定的窗口的设备环境。
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd); [System.Runtime.InteropServices.DllImport("user32.dll")]
//函数释放设备上下文环境(DC)
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
int WM_PAINT = 0xf; //要求一个窗口重画自己,即Paint事件时 /// <summary>
///
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{ base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{
IntPtr hDC = GetWindowDC(m.HWnd);
if (hDC.ToInt32() == ) //如果取设备上下文失败则返回
{
return;
} PaintComboBox(Graphics.FromHdc(hDC));
ReleaseDC(m.HWnd, hDC);
}
}
private void PaintComboBox(Graphics g)
{
g.SmoothingMode = SmoothingMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; int iDropDownButtonWidth = ;
int iDropDownButtonHeight = this.Height;
int iDropDownButtonLocatinX = ;
int iDropDownButtonLocatinY = ; if (!Util.PublicFunction.IsHigherWinXP())
{
iDropDownButtonWidth = ;
iDropDownButtonHeight = this.Height-;
iDropDownButtonLocatinX = ;
iDropDownButtonLocatinY = ;
}
//下拉按钮
Rectangle dropDownRectangle = new Rectangle(ClientRectangle.Width - iDropDownButtonLocatinX, iDropDownButtonLocatinY, iDropDownButtonWidth, iDropDownButtonHeight); //背景色刷
Brush bkgBrush; //字体色刷
Brush fcBrush; //设置背景色和字体色
bkgBrush = new SolidBrush(this._backColor);
fcBrush = new SolidBrush(this._foreColor); //画3D边框
//ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, this.Width, this.Height), Border3DStyle.SunkenInner, Border3DSide.All); int iBackColorX = ;
//为了字体正常,Enable时只是重画按钮区域
if (this.Enabled)
{
iBackColorX = this.Width - ;
}
//画背景
g.FillRectangle(bkgBrush, iBackColorX, , ClientRectangle.Width, ClientRectangle.Height); //为了字体正常,Disable时才重画文本
if (!this.Enabled)
{
//画文本
g.DrawString(base.Text, this.Font, fcBrush, , this.ClientSize.Height / , new StringFormat() { LineAlignment = StringAlignment.Center });
} //画边框
//g.DrawRectangle(_BorderPen, new Rectangle(0, 0, this.Width, this.Height));
ControlPaint.DrawBorder(g, new Rectangle(, , this.Width, this.Height), borderColor, ButtonBorderStyle.Solid); //画下拉按钮
if (Util.PublicFunction.IsHigherWinXP())
{
ControlPaint.DrawComboButton(g, dropDownRectangle, this.Enabled ? System.Windows.Forms.ButtonState.Flat : System.Windows.Forms.ButtonState.All);
}
else
{
ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, this.Enabled ? ComboBoxState.Normal : ComboBoxState.Disabled);
} g.Dispose();
bkgBrush.Dispose();
fcBrush.Dispose(); }
Winform重画ComboBox背景色的更多相关文章
- winform c#绑定combobox下拉框 年度代码。
winform c#绑定combobox下拉框 年度代码. comboBox1.Items.AddRange("});//邦定数据 comboBox1.Text = DateTime.Now ...
- winform中的ComboBox同时设置text和value的方法
winform中的ComboBox不能像webform中的dropdownlist控件一样,在属性中可以同时设置text和value值,可以通过编写一个新类来实现这个功能. 1.首先在form1中添加 ...
- 1000个圆点与PaintDC的使用,OnSize时重画很棒
import wx import random class View(wx.Panel): def __init__(self, parent): super(View, self).__init__ ...
- 重画GoogleClusterTrace数据
由于项目计划书写作需要,重画了Qi Zhang, Mohamed Faten Zhani, Raouf Boutaba, Joseph L. Hellerstein, Dynamic Heteroge ...
- winform下重画ListBox
Windows Forms是由Win32 API封装的开发组件,最初是为了替代mfc,但却没有体现与Model View Controller架构对应的特色,进而在.net framework 3.0 ...
- 重绘ComboBox —— 让ComboBox多列显示
最近在维护一个winform项目,公司购买的是DevExpress控件 (请问怎么联系DevExpress工作人员? 我想询问下,广告费是怎么给的.:p),经过公司大牛们对DevExpress控件疯狂 ...
- Winform如何实现ComboBox模糊查询
最近朋友问了一个关于Winform实现ComboBox模糊查询的知识点,自己好久没有搞Winform了,就上手练了一下,废话不多说,进入正题. 前台设计: 前台就是一个简单的Form窗体+一个Comb ...
- .Net平台Winform两个ComboBox控件绑定同一个数据源
今天WINFROM编程遇到这么一个问题:是有关WINFORM中两个comboBox控件绑定同一个数据源的问题,在窗体的界面上有两个comboBox,我在Form1_Load中对他们做了数据绑定(具体代 ...
- [C#.net]ListBox对Item进行重绘,设置背景色和前景色
别的不多说了,上代码,直接看 首先设置这行,或者属性窗口设置,这样才可以启动手动绘制,参数有三个 Normal: 自动绘制 OwnerDrawFixed:手动绘制,但间距相同 OwnerDrawVar ...
随机推荐
- HDUOJ----Good Luck in CET-4 Everybody!
Good Luck in CET-4 Everybody! Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (J ...
- Python基本数据类型详细介绍(转)
1.空(None)表示该值是一个空对象,空值是Python里一个特殊的值,用None表示.None不能理解为0,因为0是有意义的,而None是一个特殊的空值.2.布尔类型(Boolean)在 Pyth ...
- SQL Server里面导出SQL脚本(表数据的insert语句)
转载自:http://hi.baidu.com/pigarmy/blog/item/109894c445eab0a28326ac5a.html 最近需要导出一个表的数据并生成insert语句,发现SQ ...
- Android 监听 Android中监听系统网络连接打开或者关闭的实现代码
本篇文章对Android中监听系统网络连接打开或者关闭的实现用实例进行了介绍.需要的朋友参考下 很简单,所以直接看代码 复制代码 代码如下: package xxx; import android.c ...
- 最短路径 - 弗洛伊德(Floyd)算法
为了能讲明白弗洛伊德(Floyd)算法的主要思想,我们先来看最简单的案例.图7-7-12的左图是一个简单的3个顶点的连通网图. 我们先定义两个二维数组D[3][3]和P[3][3], D代表顶点与顶点 ...
- Python2 long() 函数
描述 long() 函数将数字或字符串转换为一个长整型. 语法 long() 函数语法: class long(x, base=10) 参数 x -- 字符串或数字. base -- 可选,进制数,默 ...
- 免费申请 Github 私有仓库--学生和教育人士的福利
免费申请 Github 私有仓库 -学生和教育人士的福利 Github 是全球知名的软件项目托管网站.在 Github 创建私有仓库是需要收费的,收费方案有多种,费用最小的方案是每月 7 美元的“微型 ...
- unity, Find References In Scene
材质,脚本,shader等都可以通过Find References In Scene查看引用情况,如图. 当对一个文件点击Find References In Scene后,搜索命令会显示到Scene ...
- Spring Cloud构建微服务架构(三)断路器
在分布式架构中,断路器模式的作用也是类似的,当某个服务单元发生故障(类似用电器发生短路)之后,通过断路器的故障监控(类似熔断保险丝),向调用方返回一个错误响应,而不是长时间的等待.这样就不会使得线程因 ...
- Python shell对比
对Python.shell的一些思考 如果使用python去写脚本来处理日常事务的话,相对于shell是一件比较麻烦的事情,因为我可以使用shell在花费更少的时间内,比较熟练地使用awk.sed和g ...