2014-06-16 35 views
0

我打算爲usercontrol創建一個屬性,以便根據我定義的結構設置值。下面是我用來創建結構代碼和屬性從一個結構創建一個屬性

Private fooList As List(Of Structure_Foo) 

    Public Structure Structure_Foo 
     Dim a As Integer 
     Dim b As Integer 
    End Structure 

    Public Property Foo As List(Of Structure_Foo) 
     Get 
      Return fooList 
     End Get 
     Set(ByVal value As List(Of Structure_Foo)) 
      fooList = value 
     End Set 
    End Property 

Example of the requirement

我需要能夠爲結構,從設計師的屬性窗口列表集合設置的值,如圖上面的圖片。

回答

1

你的結構更改爲

Public Structure Structure_Foo 
    Public Property a As Integer 
    Public Property b As Integer 
End Structure 

Visual Studio編輯器只列出的屬性,而不是字段。這適用於所有屬性對話框。如果您想編輯字段,您可能需要爲控件創建一個自定義設計器。

http://msdn.microsoft.com/en-us/library/h51z5c0x.aspx

+0

這不是在原來的問題,但反正是有,我可以延長Structure_Foo裏面的屬性從另一個結構到來。例如。而不是公共財產作爲整數,我怎樣才能使它像公共財產一樣作爲另一個結構。 – codeGEN

+1

當然,結構是一種類似於任何其他值的類型。然而,其屬性看起來像你想要的,你需要將你的第一個結構的屬性包裹在另一個結構周圍。我後來更新我的答案,當我回到辦公室 – Jens

+0

我在這裏發佈了一個新問題http://stackoverflow.com/questions/24241527/vb-net-setting-properties-of-user-control ..這個問題似乎並不能滿足我的要求,只是發現它遲了一點。如果你有時間的話,請友善地考慮一下。 – codeGEN