簡體   English   中英

從形式vb.net更改打開的用戶控件的GroupControl可見性

[英]change GroupControl visibility of opened usercontrol from the form vb.net

我有一個在窗體內打開的“ UserControl”,此usercontrol有一個“ GroupControl”,當用戶使用vb.net單擊存在於窗體上的按鈕時,如何隱藏或顯示此“ GroupControl”

嘗試這個 :

在您的UserControl中添加一個過程,如何設置GroupControl的可見性:

 Public sub SetVisibility (V as boolean)
     YourGroupControl.visible=v
 End Sub

以您的形式

   Public Class Form1
        Dim uc As New MyUserControl
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Controls.Add(uc)
            uc.Dock()

        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            uc.SetVisibility(False)

            'NB :MyUserControl is name of your usercontrol

        End Sub

    End Class

在用戶控件中:

Public Property GroupControlVisible() As Boolean
    Get
        Return Me.GroupControl1.Visible
    End Get
    Set(value As Boolean)
        Me.GroupControl1.Visible = value
    End Set
End Property

為了簡化,您可以使用:

MyParentForm.UserControlName1.GroupControlName.Visible = False

要么

CType(MyParentForm.Controls("UserControlName").Controls("GroupControlName"), _
                GroupControl).Visible = False

但是最好的方法是創建一個屬性,該屬性允許像這樣在UserControl類中更改GroupControl的Visible屬性:

Public Property GroupControlVisibility() As Boolean
    Get
        Return Me.GroupControlName.Visible
    End Get
    Set(value As Boolean)
        Me.GroupControlName.Visible = value
    End Set
End Property

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM