从表单 vb.net 更改打开的用户控件的 GroupControl 可见性
change GroupControl visibility of opened usercontrol from the form vb.net
我有一个 'UserControl' 在表格内打开,
这个用户控件有一个 'GroupControl'
当用户单击表单上的按钮时,如何使 'GroupControl' 隐藏或可见
使用 vb.net
试试这个:
在您的 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
Class 中 GroupControl
的可见 属性 :
Public Property GroupControlVisibility() As Boolean
Get
Return Me.GroupControlName.Visible
End Get
Set(value As Boolean)
Me.GroupControlName.Visible = value
End Set
End Property
我有一个 'UserControl' 在表格内打开, 这个用户控件有一个 'GroupControl' 当用户单击表单上的按钮时,如何使 'GroupControl' 隐藏或可见 使用 vb.net
试试这个:
在您的 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
Class 中 GroupControl
的可见 属性 :
Public Property GroupControlVisibility() As Boolean
Get
Return Me.GroupControlName.Visible
End Get
Set(value As Boolean)
Me.GroupControlName.Visible = value
End Set
End Property