繁体   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