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 ...
随机推荐
- java多线程(二)之实现Runnable接口
一.java多线程方式2: 实现Runnable接口 好处:a. 可以避免由于java单继承带来的局限性. b. 适合多个相同的程序的代码去处理同一个资源的情况, 把线程与程序的代码, 数据有效分离, ...
- no !/ in spec
问题: 在学习hibernate的过程中涉及到hibernate.cfg.xml和hibernate.hbm.xml配置文件的编写,写完之后配置文件出现黄色感叹号,鼠标悬停在感叹号上时显示no !/ ...
- HDUOJ-----2824The Euler function
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 关系数据库元数据处理类(一) 创建MSSQL元数据具体处理类
public class SqlServer : BaseMetadata { public SqlServer(string connectionString) : base(new DbUtili ...
- 三极管工作区在Spectre中的表示
三极管的工作区在Spectre中通过静态工作点的region字段表示,具体表示如下: region: 0:off 1:fwd 2:rev 3:sat 4:breakdown 可在终端中输入 : ”sp ...
- PHPEXCEL导出excel表格中长数字文本自动转为科学计数法的解决办法
方法一:前面加空格 $objActSheet->setCellValue('A1', ' '.'330602198804224688'); 方法二: $objActSheet->setCe ...
- Oracle学习笔记之一,重温范式
第一范式(1NF) 第一范式是第二和第三范式的基础,是最基本的范式.第一范式包括下列的指导原则: 数据组的每个属性只可以包含一个值. 关系中的每个数组必须只包含相同数量的值. 关系中的每个数组一定不能 ...
- 【转】input file accept属性可以限制的文件类型
来源:http://blog.sina.com.cn/s/blog_6c9d65a10101a8yh.html 在上传文件的时候,需要限制指定的文件类型. <input type="f ...
- [Jobdu] 题目1510:替换空格
题目描述: 请实现一个函数,将一个字符串中的空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 输入: 每个输入文件仅包含一组测 ...
- CentOS 7 设置中文环境
在vultr上的虚拟机虽然安装了中文支持,但是默认显示英语. 只要修改 /etc/locale.conf 即可. LANG="zh_CN.UTF-8" LANGUAGE=" ...