2009-01-29 38 views

回答

1

您必須使用所有者繪製的組合框。 This articleCodeProject是一個很好的參考。

+0

難道就沒有別的黑客或把戲呢?我相信只有爲此目的纔會有自定義控件。 – Cerebrus 2009-01-29 05:36:12

1

如果您希望在PropertyGrid中使用顏色類型屬性放置對象時提供的顏色選擇器,然後this person has done just that但是他們將其作爲具有下拉按鈕的按鈕。

如果你真的希望它是一個組合框,你不應該覺得我應該考慮太多的麻煩。

0

這裏是我的代碼用於加載的顏色列表組合供用戶選擇:

List<string> colorslist = new List<string>(); 

string[] allColors = Enum.GetNames(typeof(System.Drawing.KnownColor)); 
string[] systemEnvironmentColors = new string[(typeof(System.Drawing.SystemColors)).GetProperties().Length]; 

int index = 0; 

foreach (MemberInfo member in (typeof(System.Drawing.SystemColors)).GetProperties()) 
{ 
    systemEnvironmentColors[index++] = member.Name; 
} 

foreach (string color in allColors) 
{ 
    if (Array.IndexOf(systemEnvironmentColors, color) < 0) 
    { 
        colorslist .Add(color); 
    } 
} 

cboColors.DataSource = colorslist; 
相關問題