c#構(gòu)造ColorComboBox(顏色下拉框)
class ColorComboBox : ComboBox
{
/// <summary>
/// 當(dāng)前選中色
/// </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è)置默認(rèn)色
}
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)) //預(yù)留下拉項(xiàng)間距
{
e.Graphics.FillRectangle(b, rect.X, rect.Y + 2, rect.Width, rect.Height - 4);
}
}
}
- C# ComboBox控件“設(shè)置 DataSource 屬性后無(wú)法修改項(xiàng)集合”的完美解決方法
- C#實(shí)現(xiàn)帶搜索功能的ComboBox
- C# 重寫(xiě)ComboBox實(shí)現(xiàn)下拉任意組件的方法
- C# ComboBox的聯(lián)動(dòng)操作(三層架構(gòu))
- C#實(shí)現(xiàn)ComboBox控件顯示出多個(gè)數(shù)據(jù)源屬性的方法
- C#實(shí)現(xiàn)綁定Combobox的方法
- C#用ComboBox控件實(shí)現(xiàn)省與市的聯(lián)動(dòng)效果的方法
- C#(WinForm) ComboBox和ListBox添加項(xiàng)及設(shè)置默認(rèn)選擇項(xiàng)
- C# listview添加combobox到單元格的實(shí)現(xiàn)代碼
- C#實(shí)現(xiàn)ComboBox自動(dòng)匹配字符
- C#中comboBox實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)
相關(guān)文章
C#調(diào)用百度翻譯實(shí)現(xiàn)翻譯HALCON的示例
HALCON示例程序的描述部分一直是英文的,看起來(lái)很不方便。本文就使用百度翻譯實(shí)現(xiàn)翻譯HALCON,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06Unity5.6大規(guī)模地形資源創(chuàng)建方法
這篇文章主要為大家詳細(xì)介紹了Unity5.6大規(guī)模地形資源創(chuàng)建方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02解決C#中WebBrowser的DocumentCompleted事件不執(zhí)行的實(shí)現(xiàn)方法
本篇文章是對(duì)C#中WebBrowser的DocumentCompleted事件不執(zhí)行解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Unity游戲開(kāi)發(fā)實(shí)現(xiàn)背包系統(tǒng)的示例詳解
這篇文章主要為大家介紹了Unity游戲開(kāi)發(fā)實(shí)現(xiàn)背包系統(tǒng)的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08