手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#构造ColorComboBox(颜色下拉框)
c#构造ColorComboBox(颜色下拉框)
摘要:复制代码代码如下:classColorComboBox:ComboBox{//////当前选中色///publicColorSelected...

复制代码 代码如下:

class ColorComboBox : ComboBox

{

/// <summary>

/// 当前选中色

/// </summary>

public Color SelectedColor

{

get { return Color.FromName(this.Text); }

}

/// <summary>

/// 构造函数,构造颜色下拉列表

/// </summary>

public ColorComboBox()

{

this.DrawMode = DrawMode.OwnerDrawFixed;

this.DropDownStyle = ComboBoxStyle.DropDownList;

this.ItemHeight = 25;

PropertyInfo[] propInfoList = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);

foreach (PropertyInfo c in propInfoList)

{

this.Items.Add(c.Name);

}

this.Text = "Black"; //设置默认色

}

protected override void OnDrawItem(DrawItemEventArgs e)

{

Rectangle rect = e.Bounds;

if (e.Index >= 0)

{

string colorName = this.Items[e.Index].ToString();

Color c = Color.FromName(colorName);

using (Brush b = new SolidBrush(c)) //预留下拉项间距

{

e.Graphics.FillRectangle(b, rect.X, rect.Y + 2, rect.Width, rect.Height - 4);

}

}

}

【c#构造ColorComboBox(颜色下拉框)】相关文章:

C#基础概念二十五问 16-20

WinForm中的登录实现

C#中控制远程计算机的服务的方法

C#难点逐个击破(7):checked与unchecked

C#的四个基本技巧

C#中计算时间差中的小数问题解决

C#学习基础概念二十五问 11-15

winfrom 打印表格 字符串的封装实现代码 附源码下载

c# 深拷贝与浅拷贝的区别分析及实例

C#的编码规范详细说明

精品推荐
分类导航