从表单vb.net更改已打开的usercontrol的GroupControl可见性

时间:2016-05-05 07:43:13

标签: vb.net devexpress

我在表单中打开了一个'UserControl', 这个usercontrol有一个'GroupControl' 当用户单击表单上的按钮时,如何使“GroupControl”隐藏或可见 使用vb.net

3 个答案:

答案 0 :(得分:1)

试试这个:

在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

答案 1 :(得分:1)

在用户控件中:

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

答案 2 :(得分:-2)

要简化,您可以使用:

MyParentForm.UserControlName1.GroupControlName.Visible = False

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

但最好的方法是创建一个属性,允许更改GroupControl类中UserControl的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