2011-09-16 65 views
0

我已經編寫了一個將控件添加到窗體的Visual Studio 2008插件。我想其中的一些控件的Visible屬性設置爲false,以便他們在運行時隱藏的,所以我這樣做:如何使Visual Studio插件在設計器中設置控件的Visible屬性

If hiddenControls.Contains(.ColumnName) Then 'hiddenControls is TypeOf List(Of String) 
    fieldControlAsControl.Visible = False 'TypeOf Control 
End If 

這是行不通的。該控件不僅在設計器窗口本身中是不可見的,而且.Visible = False代碼甚至不會將它變成[FormName] .designer.vb。

我試圖迫使系列化上像這樣的Visible屬性,但無濟於事:

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _ 
Public Shadows Property Visible() As Boolean 
    Get 
     Return MyBase.Visible 
    End Get 
    Set(ByVal value As Boolean) 
     MyBase.Visible = value 
    End Set 
End Property 

誰能幫我迫使Visible屬性在我的插件被序列化?

回答

1

我發現了一個比較好的解決方法('好',這意味着它不覺得非常不合適)。我下面的代碼添加到該得到的我的插件添加到窗體控件:

<System.ComponentModel.Browsable(False)> _ 
Public Overloads Property Visible() As Boolean 
    Get 
     Return MyBase.Visible 
    End Get 
    Set(ByVal value As Boolean) 
     MyBase.Visible = value 
    End Set 
End Property 

<System.ComponentModel.Category("Appearance")> _ 
<System.ComponentModel.Description("Whether the FieldControl will be visible at runtime.")> _ 
<System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _ 
<System.ComponentModel.Browsable(True)> _ 
Public Property VisibleAtRunTime() As Boolean 
    Get 
     Return mVisibleAtRunTime 
    End Get 
    Set(ByVal value As Boolean) 
     mVisibleAtRunTime = value 
     If Not DesignMode Then 
      Visible = value 
     End If 
    End Set 
End Property 

我然後讓插件設置,而不是「可見」屬性「VisibleAtRunTime」屬性。

相關問題