c#構(gòu)造ColorComboBox(顏色下拉框)
class ColorComboBox : ComboBox
{
/// <summary>
/// 當前選中色
/// </summary>
public Color SelectedColor
{
get { return Color.FromName(this.Text); }
}
/// <summary>
/// 構(gòu)造函數(shù),構(gòu)造顏色下拉列表
/// </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"; //設(shè)置默認色
}
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# ComboBox控件“設(shè)置 DataSource 屬性后無法修改項集合”的完美解決方法
- C#實現(xiàn)帶搜索功能的ComboBox
- C# 重寫ComboBox實現(xiàn)下拉任意組件的方法
- C# ComboBox的聯(lián)動操作(三層架構(gòu))
- C#實現(xiàn)ComboBox控件顯示出多個數(shù)據(jù)源屬性的方法
- C#實現(xiàn)綁定Combobox的方法
- C#用ComboBox控件實現(xiàn)省與市的聯(lián)動效果的方法
- C#(WinForm) ComboBox和ListBox添加項及設(shè)置默認選擇項
- C# listview添加combobox到單元格的實現(xiàn)代碼
- C#實現(xiàn)ComboBox自動匹配字符
- C#中comboBox實現(xiàn)三級聯(lián)動
相關(guān)文章
同時兼容JS和C#的RSA加密解密算法詳解(對web提交的數(shù)據(jù)加密傳輸)
這篇文章主要給大家介紹了關(guān)于同時兼容JS和C#的RSA加密解密算法,通過該算法可以對web提交的數(shù)據(jù)進行加密傳輸,文中通過圖文及示例代碼介紹的非常詳細,需要的朋友們可以參考借鑒,下面來一起看看吧。2017-07-07
c#使用Dataset讀取XML文件動態(tài)生成菜單的方法
這篇文章主要介紹了c#使用Dataset讀取XML文件動態(tài)生成菜單的方法,涉及C#使用Dataset操作XML文件的相關(guān)技巧,需要的朋友可以參考下2015-05-05

