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 ...
随机推荐
- 将Gradle项目公布到maven仓库
将Gradle项目公布到maven仓库 1 Gradle简单介绍 1.1 Ant.Maven还是Gradle? 1.1.1 Ant和Maven介绍 全称为Apache Maven,是一个软件(特别是J ...
- Object-c中block需要注意的几点问题
1. Block定义 1) 说明: a. Block是OC中的一种数据类型,在iOS开发中被广泛使用 b. ^是Block的特有标记 c. Block的实现代码包含在{}之间 d. 大多情况下,以内联 ...
- WPF基础学习第一天
格式 1.XAML格式: <Button x:Name="btnClick" Content="按钮" HorizontalAlignment=" ...
- mermaid 语法
a:focus { outline: thin dotted #333; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2p ...
- spring-integration-kafka
1.pom.xml配置 <dependency> <groupId>org.springframework.integration</groupId> <ar ...
- python matplotlib.pyplot画矩形图 以及plt.gca()
plt的Rectangle参数: 第一个参数是坐标(x,y),即矩形的画图的起点坐标,这个起点坐标不是一味地从左下角开始画,而是对应整个图中坐标原点,即(0,0). 第二个参数是矩形宽度 第三个坐标是 ...
- Fort.js – 时尚、现代的进度提示效果
Fort.js 是表单填写进度提示效果的 JavaScript 库.使用很easy. 提供了Default.Gradient.Sections 以及 Flash 四种效果 用Fort.js非常easy ...
- IDLE经常使用快捷键汇总
IDLE(An Integrated DeveLopment Environment for Python)是Python自带的编译器,在刚開始学习的人,或写小程序,或用于验证的时候,经经常使用到!假 ...
- Spring +quartz获取ApplicationContext上下文
job存在数据库中,能够进行动态的增增删改查,近期遇到了怎样获取ApplicationContext上下文的问题.解决的方法例如以下 applicationContext-quartz.xml < ...
- Android IPC机制(三)在Android Studio中使用AIDL实现跨进程方法调用
在上一篇文章Android IPC机制(二)用Messenger进行进程间通信中我们介绍了使用Messenger来进行进程间通信的方法.可是我们能发现Messenger是以串行的方式来处理client ...