[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. 3D 坐标变换 公式 推导

    [ 更新 ]更好的方法见[用抽象代数讨论仿射变换和仿射空间中的坐标变换] ,以下是之前的内容. 以下的推导 结论是正确的,可是过程有点懵. 以下使用行向量: e1=(1,0,0) e2=(0,1,0) ...

  2. java springMVC 报400错误问题

    java springMVC 中如果报400错误 很有可能是因为时间转换的问题. 我在项目中就遇到了这个问题,是因为我少引用了一个库,如果是因为时间问题的话添加以下依赖就可以解决. <depen ...

  3. 二层交换机当三层交换机,使用单臂路由实现二层交换机上的VLAN互通

    众多中小企业内部网络结构都很简单,仅仅是用一台交换机将所有员工机以及服务器连接到一起,然后通过光纤访问internet而已.当然为了保证部分主机的安全性以及分割内部广播包提高网络传输速度,采取诸如划分 ...

  4. leetcode mock interview-two sum II

    package com.company; import java.util.LinkedList; import java.util.List; public class Main { public ...

  5. GOOGLE突破图书馆入口IP限制之技巧

    很多图书馆都要注册或要本地IP才能浏览或下载图书,有没有另类的快速办法能快速突破图书馆的入口,能随意地下载图书呢? 希望大家在GOOGLE里试试这个:“index of/ ” inurl:lib 你将 ...

  6. Jackson 练习(一)

    package com.yc.model; /** * 班级 * @author Administrator * */ public class ClassModel { private String ...

  7. HTML-<a>标签添加下划线

    <a href="ddrb/090630.asp" target="_blank" style="text-decoration:underli ...

  8. Android Studio中mac上面的安装

    Android Studio中mac上面的安装 学习了:https://blog.csdn.net/xianrenli38/article/details/79347170 http://www.an ...

  9. 推荐8款HTML5相关的特殊效果

    HTML5是HTML的升级版,HTML5有两大特点:首先,强化了 Web 网页的表现性能.其次,追加了本地数据库等 Web 应用的功能.广义论及HTML5时,实际指的是包括HTML.CSS和JavaS ...

  10. C#应用视频教程2.1 OPENGL虚拟仿真介绍

    OPENGL的虚拟仿真对于工控自动化的意义很大,虽然市面上有很多的第三方软件比如Solidworks,Mathlab,ProE等等软件可以做仿真,而且能够实现的功能包括了流体分析,力学分析,摩擦力分析 ...