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 ... 
随机推荐
- CentOS下Storm 1.0.0集群安装具体解释
			本文环境例如以下: 操作系统:CentOS 6 32位 ZooKeeper版本号:3.4.8 Storm版本号:1.0.0 JDK版本号:1.8.0_77 32位 python版本号:2.6.6 集群 ... 
- Android网络开发之HttpClient
			Apache提供HttpClient,它对java.net中的类做了封装和抽象,更适合在Android上开发应用. HttpClient应用开发几个类: 1. ClientConnectionMana ... 
- hduoj----(1033)Edge
			Edge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ... 
- HDUOJ---hello Kiki
			Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ... 
- 【LeetCode】137. Single Number II (3 solutions)
			Single Number II Given an array of integers, every element appears threetimes except for one. Find t ... 
- android中完全退出当前应用程序的四种方法
			Android程序有很多Activity,比如说主窗口A,调用了子窗口B,如果在B中直接finish(), 接下里显示的是A.在B中如何关闭整个Android应用程序呢?本人总结了几种比较简单的实现方 ... 
- exec系列函数和system函数
			一.exec替换进程映象 在进程的创建上Unix采用了一个独特的方法,它将进程创建与加载一个新进程映象分离.这样的好处是有更多的余地对两种操作进行管理.当我们创建 了一个进程之后,通常将子进程替换成新 ... 
- Python 列表 reverse() 方法
			描述 Python 列表 reverse() 方法对列表中的元素进行反向排序. 语法 reverse() 方法语法: L.reverse() 参数 无. 返回值 该方法没有返回值,但是会对列表的元素进 ... 
- jquery autoComplete 插件
			github: https://github.com/Pixabay/jQuery-autoComplete/blob/master/demo.html 官网demo https://goodies. ... 
- 【JEECG_3.7.1】列表多表头的设计
			先看下多表头的设计: 在这个多表头的表单当中,我们可以按照从上到下和从左往右的划分方式,将表头划分成三行十列,分别是: 列表标签 人员信息.部门信息.工资.入职状态.创建日期.操作 名称.年龄.性别. ... 
