//返回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背景色的更多相关文章

  1. winform c#绑定combobox下拉框 年度代码。

    winform c#绑定combobox下拉框 年度代码. comboBox1.Items.AddRange("});//邦定数据 comboBox1.Text = DateTime.Now ...

  2. winform中的ComboBox同时设置text和value的方法

    winform中的ComboBox不能像webform中的dropdownlist控件一样,在属性中可以同时设置text和value值,可以通过编写一个新类来实现这个功能. 1.首先在form1中添加 ...

  3. 1000个圆点与PaintDC的使用,OnSize时重画很棒

    import wx import random class View(wx.Panel): def __init__(self, parent): super(View, self).__init__ ...

  4. 重画GoogleClusterTrace数据

    由于项目计划书写作需要,重画了Qi Zhang, Mohamed Faten Zhani, Raouf Boutaba, Joseph L. Hellerstein, Dynamic Heteroge ...

  5. winform下重画ListBox

    Windows Forms是由Win32 API封装的开发组件,最初是为了替代mfc,但却没有体现与Model View Controller架构对应的特色,进而在.net framework 3.0 ...

  6. 重绘ComboBox —— 让ComboBox多列显示

    最近在维护一个winform项目,公司购买的是DevExpress控件 (请问怎么联系DevExpress工作人员? 我想询问下,广告费是怎么给的.:p),经过公司大牛们对DevExpress控件疯狂 ...

  7. Winform如何实现ComboBox模糊查询

    最近朋友问了一个关于Winform实现ComboBox模糊查询的知识点,自己好久没有搞Winform了,就上手练了一下,废话不多说,进入正题. 前台设计: 前台就是一个简单的Form窗体+一个Comb ...

  8. .Net平台Winform两个ComboBox控件绑定同一个数据源

    今天WINFROM编程遇到这么一个问题:是有关WINFORM中两个comboBox控件绑定同一个数据源的问题,在窗体的界面上有两个comboBox,我在Form1_Load中对他们做了数据绑定(具体代 ...

  9. [C#.net]ListBox对Item进行重绘,设置背景色和前景色

    别的不多说了,上代码,直接看 首先设置这行,或者属性窗口设置,这样才可以启动手动绘制,参数有三个 Normal: 自动绘制 OwnerDrawFixed:手动绘制,但间距相同 OwnerDrawVar ...

随机推荐

  1. 用zd1211+Ubuntu 10.04实现的AP

    [日期:2010-06-24]   zd1211 在Ubuntu 10.04 LTS上的master mode 的问题解决之后,理论上就可以把zd1211 USB网卡用来做一个AP了,实际上还有几个问 ...

  2. Windows系统开机硬盘自检问题解决

    http://blog.sina.com.cn/s/blog_49063a0b0100tf7y.html硬盘开机自检通常都是由于计算机使用者的不合理使用电脑造成的,比如非常正关机,或者遭到病毒侵袭,抑 ...

  3. 修改注册表值解决ie被恶意窜改的问题

    修改注册表值解决ie被恶意窜改的问题 IE消失 运行—Regedit 主键HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDes ...

  4. 阿里云ECS服务器Linux环境下配置php服务器(一)--基础配置篇

    开始安装软件了,我们需要安装的软件有apache,php和MySQL. ps:如果你购买的是北京的服务器,有个安全组需要设置,我全部用的默认设置,暂时还没发现会有什么影响. 首先关闭SELINUX(S ...

  5. 设置当前Activity的屏幕亮度

    设置当前的Activity的屏幕亮度,而不是设置系统的屏幕亮度,退出当前的Activity后恢复系统的亮度. 直接看代码好了 Java代码 WindowManager.LayoutParams lp  ...

  6. Android开发学习之3大类菜单

    在Android系统中,菜单可以分为三类:选项菜单(Option Menu),上下文菜单(Context Menu)以及子菜单(Sub Menu). 一.选项菜单(Option Menu) 创建选项菜 ...

  7. 关于ftpshell脚本中mget中去除多余交互式提示的方法

    默认情况下ftp里面的交互式提示是开启的,平常如果下载多个文件时,这种提示很让人烦,如果是在shell脚本里面要从ftp服务器上一次mget多个文件,写个交互式很麻烦,最好是把这个交互式提示关掉. 进 ...

  8. OAF_OAF控件系列3 - AdvancedTable的实现(案例)

    2014-06-02 Created By BaoXinjian

  9. mysql添加和root用户一样的权限

    以下语句具有和ROOT用户一样的权限.大家在拿站时应该碰到过.root用户的mysql,只可以本地连,对外拒绝连接.以下方法可以帮助你解决这个问题了,下面的语句功能是,建立一个用户为monitor密码 ...

  10. News summary on C# and .NET

    (keep updating...) Roslyn http://blogs.msdn.com/b/ericlippert/archive/2012/06/05/announcing-microsof ...