2009-02-05 25 views
2

我知道這可能是一個noob問題,但是它讓我感到困惑。NET中屬性的限制值

比方說,我有我在.aspx頁面中引用一個用戶控件:

<uc:somecontrol runat="server" id="uc1" property1="red" /> 

我如何使它所以當VS05智能感知會顯示類似「紅色」,「綠色」的選項, 「藍色」爲property1?與您想要在文本框上的模式「文本」,「多行」和「密碼」之間進行選擇的方式類似。我正在使用VB。

謝謝!

回答

14

使您的屬性成爲枚舉而不是字符串。

Enum ControlColor 
Red = 1 
Blue = 2 
Green = 3 
End Enum 

Public Property MyProperty As ControlColor 
5

在一個新的文件作爲雷克斯定義枚舉說:

Public Enum ControlColor 
    Red = 1 
    Blue = 2 
    Green = 3 
End Enum 

然後在你的控制,定義你的財產是這樣的(我的VB語法是生鏽,但我認爲這是對的):

Private _color As ControlColor 

Public Property [Color] As ControlColor 
    Get 
     Return _color 
    End Get 
    Set (ByVal value As ControlColor) 
     _color = value 
    End Set 
End Property 
+0

謝謝max,儘管雷克斯擊敗你! – Jason 2009-02-05 15:43:21