简体   繁体   中英

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

我有一个在窗体内打开的“ UserControl”,此usercontrol有一个“ GroupControl”,当用户使用vb.net单击存在于窗体上的按钮时,如何隐藏或显示此“ GroupControl”

Try this :

In you UserControl add a procedure how set visibility to your GroupControl :

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

In your form

   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

In the user control:

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

To Simplify, you can use :

MyParentForm.UserControlName1.GroupControlName.Visible = False

or

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

But the best way is create a property which allows changing the Visible property of the GroupControl in UserControl Class like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM