[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. 《Hadoop应用开发技术详解》

    <Hadoop应用开发技术详解> 基本信息 作者: 刘刚 丛书名: 大数据技术丛书 出版社:机械工业出版社 ISBN:9787111452447 上架时间:2014-1-10 出版日期:2 ...

  2. GPGPU OpenCL使用结构体数据

    OpenCL编程中可以使用结构体,只需要在核函数kernel中提供同样的结构体申明就可以啦. 如果在主函数中定义了结构体: typedef struct studentNode{ int age; f ...

  3. tm标准mvc框架对应robotlegs 的mvc

    tm标准mvc框架对应robotlegs 的mvc+s (其实都是一样样滴)

  4. 使用 FOR XML PATH 產生 XML 格式時,遇到 NULL 該如何處理?

    當您嘗試利用 FOR XML PATH 產生 XML 格式時,若遇到 Result Set 為 Null 時,會導致整個查詢結果為 Null ,若您想要在查不到資料時,可以顯示自訂的內容,本文將提供可 ...

  5. linux下tar.gz、tar、bz2、zip、 xz、rar等解压缩、压缩命令小结

    http://www.jb51.net/LINUXjishu/43356.html unrar x aa.rarunrar e aa.rarx参数 是解压到一个文件夹里 e参数是把所有文件解压到当前目 ...

  6. Array.prototype.slice.call 和 slice以及call

    单独的简单介绍,后续再补上一些资料. 对象转换为数组. /** * slice : 数组->slice(截取) * 参数有两个,开始截取和结束截取,并返回原数组: * a.slice(1) || ...

  7. Xcode 打包 ipa 包

    原地址:http://zengwu3915.blog.163.com/blog/static/27834897201362831449893/ 上次介绍了木有证书的打包ipa.如果安装证书后,我们还有 ...

  8. QtGui.QSlider

    A QtGui.QSlider is a widget that has a simple handle. This handle can be pulled back and forth. This ...

  9. Call to a member function select() on string错误

    Call to a member function select() on string错误 Call to a member function select() on array错误 我也是 Get ...

  10. WCF学习笔记之可靠会话

    可靠会话传输需要解决两个问题:重复消息和无序交付:制定WS-RM的一个主要目的就是实现一种模块化 的可靠消息传输机制:WS-RM两个版本(WS-RM1.0和WS-RM1.1): WCF中整个可靠会话的 ...