Ownerdrawn ComboBox
[ToolboxBitmap(typeof(ComboBox))]
class ComboBoxEx : ComboBox
{
public ComboBoxEx()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
this.DrawItem += ComboBoxEx_DrawItem;
this.DropDownBorderColor = Color.Red;
this.DropDownBackColor = Color.Yellow;
} [Category("Appearance")]
[Description("The border color of the drop down list")]
[DefaultValue(typeof(Color), "Red")]
public Color DropDownBorderColor { get; set; } [Category("Appearance")]
[Description("The background color of the drop down list")]
[DefaultValue(typeof(Color), "Yellow")]
public Color DropDownBackColor { get; set; } void ComboBoxEx_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < )
return; if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
return // Draw the background of the item.
if (
((e.State & DrawItemState.Focus) == DrawItemState.Focus) ||
((e.State & DrawItemState.Selected) == DrawItemState.Selected) ||
((e.State & DrawItemState.HotLight) == DrawItemState.HotLight)
)
{
e.DrawBackground();
}
else
{
Brush backgroundBrush = new SolidBrush(DropDownBackColor);
e.Graphics.FillRectangle(backgroundBrush, e.Bounds);
} //Draw item text
e.Graphics.DrawString(Items[e.Index].ToString(), this.Font, Brushes.Black,
new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); // Draw the focus rectangle if the mouse hovers over an item.
if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
e.DrawFocusRectangle(); //Draw the border around the whole DropDown area
Pen borderPen = new Pen(DropDownBorderColor, );
Point start;
Point end; if (e.Index == )
{
//Draw top border
start = new Point(e.Bounds.Left, e.Bounds.Top);
end = new Point(e.Bounds.Left + e.Bounds.Width - , e.Bounds.Top);
e.Graphics.DrawLine(borderPen, start, end);
} //Draw left border
start = new Point(e.Bounds.Left, e.Bounds.Top);
end = new Point(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height - );
e.Graphics.DrawLine(borderPen, start, end); //Draw Right border
start = new Point(e.Bounds.Left + e.Bounds.Width - , e.Bounds.Top);
end = new Point(e.Bounds.Left + e.Bounds.Width - , e.Bounds.Top + e.Bounds.Height - );
e.Graphics.DrawLine(borderPen, start, end); if (e.Index == Items.Count - )
{
//Draw bottom border
start = new Point(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height - );
end = new Point(e.Bounds.Left + e.Bounds.Width - , e.Bounds.Top + e.Bounds.Height - );
e.Graphics.DrawLine(borderPen, start, end);
}
}
}
Ownerdrawn ComboBox的更多相关文章
- C# WinForm开发系列 - ComboBox
5.一个带CheckBox,分组,颜色标记等功能的下拉框 PowerComboBoxCSharp.rar 包含自动完成下拉框,字体下拉框,电脑盘符,多列下拉框,带CheckBox,树型下拉框等.代码 ...
- Extjs 让combobox写起来更简单
也已经写了很久时间的extjs ,每次都用到很多的combobox,配置很多东西觉得实在是太麻烦,所以根据常用到的情况写了一个简便的combobox,再次记录下来,以免放在某个地方忘记了找不到了. 定 ...
- ASP.NET Aries JSAPI 文档说明:AR.Form、AR.Combobox
AR.Form 文档 1:对象或属性: 名称 类型 说明 data 属性 编辑页根据主键请求回来的数据 method 属性 用于获取数据的函数指向,默认值Get objName 属性 用于拦截form ...
- 带搜索的ComboBox
带搜索的ComboBox就是给ComboBox一个依赖属性的ItemSource,然后通过数据源中是否包含要查询的值,重新给ComboBox绑定数据源. public class EditComboB ...
- 【MVVM DEV】DataColumn中的TextBox与ComboBox的并存
一.前言 在WPF编程中,有时候我们使用DataGrid会需要在一个DataColumn中既有TextBox,也要有ComboBox或者TextBlock等其他数据显示样式. 这个时候我们 ...
- [WinForm] DataGridView 绑定 DT && ComboBox 列绑定 Dict
一 需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面 ...
- EasyUI combobox
高度自适应 data-options="required:true,editable:false,panelHeight:'auto',panelMaxHeight:170" 加上 ...
- 【WPF】Combobox指定选中值用selectedValue不是很灵的时候,
wpf combobox 指定选中的值,前题,combobox是通过数据库绑定的ItemsSource:所以再指定的时候用selectValue不是很成功!我的解决方法是 生成一个字典,办值和索引对应 ...
- 下拉框-ComboBox
<ComboBox Name="cbBox" SelectionChanged="cbBox_SelectionChanged"></Comb ...
随机推荐
- Java效率工具之Lombok
参考: http://www.54tianzhisheng.cn/2018/01/09/lombok/ https://zhuanlan.zhihu.com/p/32779910
- MySQL索引优化案例
这里我们分成三种情况进行分析,分别是单表,两表,三表 1.单表 CREATE TABLE IF NOT EXISTS `article`( `id` ) NOT NULL PRIMARY KEY AU ...
- [转]nginx折腾记(HTTP性能能测试,与Apache对比)
话说nginx在大压力的环境中比apache的表现要好,于是下载了一个来折腾一下. 下载并编译安装,我的编译过程有点特别: 1.去除调试信息,修改$nginx_setup_path/auto/cc ...
- GPGPU OpenCL使用结构体数据
OpenCL编程中可以使用结构体,只需要在核函数kernel中提供同样的结构体申明就可以啦. 如果在主函数中定义了结构体: typedef struct studentNode{ int age; f ...
- IE6BUG汇总篇(不断更新)
1.IE6双倍边距bug 当页面内有多个连续浮动时,如本页的图标列表是采用左浮动,此时设置li的左侧margin值时,在最左侧呈现双倍情况.如外边距设置为10px, 而左侧则呈现出20px,解决它的方 ...
- Quartz学习笔记
:30发送email通知客户最新的业务情况. java.util.Timer和java.util.TimerTask Timer和TimerTask是能够完毕job schedule的两个jdk ...
- XMPPFrameWork IOS 开发(四)消息和好友上下线
原始地址:XMPPFrameWork IOS 开发(四) 消息 //收到消息 - (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XM ...
- GetXamarin.xambe
GetXamarin.xambe <!DOCTYPE html> <html lang="en" class=""> <head& ...
- SCU 4313 把一棵树切成每段K个点 (n%k)剩下的点不管
题目链接:http://cstest.scu.edu.cn/soj/problem.action?id=4313 判断是不是存在拆图得到新连通分支的点个数是K的倍数 注意一个点所连的边只能被切一条 # ...
- UNIX网络编程读书笔记:字节操纵函数
#include <strings.h> void bzero(void *dest, size_t nbytes); void bcopy(const void *src, void * ...