2011-05-12 59 views
1

我有這個屬性的默認值。任何人都可以幫助我如何有一個下拉菜單選擇值?我要上降下來的值纔會出現只有1-10 ...使用下拉菜單在C#中添加控件屬性

private int _margin = 10; 

[Bindable(true), Category(_category), DefaultValue(10)] 
public int MarginWidth 
{ 
    get { return _margin; } 
    set { _margin = Math.Abs(value); Invalidate(); } 
} 

img

反正,你怎麼把這種[Bindable(true), Category(_category), DefaultValue(10)] 只是爲谷歌搜索參考關鍵?

+0

對不起,我用它作爲例子..實際上我想添加一個控件屬性像ButtonSet:然後在下拉菜單中,有選項「設置A」,「設置B」,「設置C」..等.. – 2011-05-12 03:55:44

回答

1

方括號中的每個項目是Attributes,例如。 BindableAttribute,CategoryAttributeDefaultValueAttribute

簡而言之,屬性用於將metadata附加到方法。屬性的創建者可以完全定義哪些信息。這些屬性可以通過反射和訪問它們的數據再次獲得。上面鏈接的Attribute類的文檔中,有很多關於使用信息等

+0

我可以問示例代碼綁定控制屬性中的多個數據? – 2011-05-12 03:44:59

+0

@vrynxzent:我創建自己的'Control'並沒有做太多工作,所以我無法幫助你,抱歉。 – 2011-05-12 03:49:54

+0

@vrynxzent:最好的辦法是查看'System.ComponentModel。* Attribute'類,看看有沒有什麼可以幫助你,因爲我認爲你幾乎在這裏正確的軌道上。 – 2011-05-12 03:50:49