[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的更多相关文章

  1. C# WinForm开发系列 - ComboBox

    5.一个带CheckBox,分组,颜色标记等功能的下拉框  PowerComboBoxCSharp.rar 包含自动完成下拉框,字体下拉框,电脑盘符,多列下拉框,带CheckBox,树型下拉框等.代码 ...

  2. Extjs 让combobox写起来更简单

    也已经写了很久时间的extjs ,每次都用到很多的combobox,配置很多东西觉得实在是太麻烦,所以根据常用到的情况写了一个简便的combobox,再次记录下来,以免放在某个地方忘记了找不到了. 定 ...

  3. ASP.NET Aries JSAPI 文档说明:AR.Form、AR.Combobox

    AR.Form 文档 1:对象或属性: 名称 类型 说明 data 属性 编辑页根据主键请求回来的数据 method 属性 用于获取数据的函数指向,默认值Get objName 属性 用于拦截form ...

  4. 带搜索的ComboBox

    带搜索的ComboBox就是给ComboBox一个依赖属性的ItemSource,然后通过数据源中是否包含要查询的值,重新给ComboBox绑定数据源. public class EditComboB ...

  5. 【MVVM DEV】DataColumn中的TextBox与ComboBox的并存

    一.前言       在WPF编程中,有时候我们使用DataGrid会需要在一个DataColumn中既有TextBox,也要有ComboBox或者TextBlock等其他数据显示样式. 这个时候我们 ...

  6. [WinForm] DataGridView 绑定 DT && ComboBox 列绑定 Dict

    一  需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面 ...

  7. EasyUI combobox

    高度自适应 data-options="required:true,editable:false,panelHeight:'auto',panelMaxHeight:170" 加上 ...

  8. 【WPF】Combobox指定选中值用selectedValue不是很灵的时候,

    wpf combobox 指定选中的值,前题,combobox是通过数据库绑定的ItemsSource:所以再指定的时候用selectValue不是很成功!我的解决方法是 生成一个字典,办值和索引对应 ...

  9. 下拉框-ComboBox

    <ComboBox Name="cbBox" SelectionChanged="cbBox_SelectionChanged"></Comb ...

随机推荐

  1. 数学图形(2.15)Spherical sinusoid球面正弦曲线

    这个曲线与之前的数学图形(2.7)sphere sine wave很相似.而且个人觉得从其公式上看sphere sine wave更应该叫做球面正弦曲线.当然从渲染的曲线图上看,它是非常明显的贴在球上 ...

  2. Fragment 简介 基础知识 总结 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. 网络地址转换相关函数使用(inet_addr,inet_ntoa,inet_addr)

    aa 相关函数原型及参数类型: 函数原型:int inet_aton(const char *cp, struct in_addr *inp); in_addr_t inet_addr(const c ...

  4. PHP 5 时区

    PHP 5 时区 PHP 支持的时区 下面是 PHP 支持的时区的完整列表,这些对一些 PHP 日期函数很有用. 非洲 美洲 南极洲 北冰洋 亚洲 大西洋 大洋洲 欧洲 印度洋 太平洋 非洲 Afri ...

  5. 算法笔记_032:最长回文串(Java)

    目录 1 问题描述 2 解决方案 2.1 中心扩展法 2.2 Manacher算法   1 问题描述 给定一个字符串,求它的最长回文子串的长度. 2 解决方案 2.1 中心扩展法 此处,首先枚举出回文 ...

  6. QtGui.QGridLayout

    The most universal layout class is the grid layout. This layout divides the space into rows and colu ...

  7. Js中/g \s 什么意思

    Js中/g \s 什么意思 js里elm.value.replace(/[\s ]+/g, ''),是什么意思 比如/[\s]是什么意思 elm是表单吧.将elm表单的值中的空白字符替换 replac ...

  8. POJ 3463 Sightseeing

    最短路+次短路(Dijkstra+priority_queue) 题意是要求你找出最短路的条数+与最短路仅仅差1的次短路的条数. 開始仅仅会算最短路的条数,和次短路的长度.真是给次短路条数跪了.ORZ ...

  9. linux中echo的使用方法

    1.echo命令我们经常使用的选项有两个,一个是-n,表示输出之后不换行.另外一个是-e,表示对于转义字符按对应的方式处理,假设不加-e那么对于转义字符会按普通字符处理. 2.echo输出时的转义字符 ...

  10. 【LeetCode】101. Symmetric Tree (2 solutions)

    Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...