用户控件从父窗体调用方法
User Control calling a method from the parent form
您好,我正在创建一个用户控件,用于确定是启用还是禁用主(父)窗体上的特定按钮。
理想情况下,当 UC 上的条件得到满足时,我会从父窗体调用一个方法来设置状态。但那是行不通的。
我怎样才能做到这一点?
主窗体(form_load):
Dim myTSButton As New ToolStripButton
With myTSButton
.Text = ""
.Image = Icons.My.Resources.myIcon.ToBitmap
.Enabled = False
AddHandler .Click, AddressOf myTSButton_Click
.Name = "myTSButton"
tStrip.Items.Add(myTSButton)
End With
UC 将显示一些复选框,选择这些复选框可能会启用或禁用此 myTSButton。
If ConditionsAreMet Then
'Enable the myTSButton on my parent form!
End If
If ConditionsAreMet Then
Dim btn As ToolStripItem = CType(tStrip.Items.Find("myTSButton", True).ElementAt(0), ToolStripItem)
btn.Enabled = True
End If
用 VB2010 测试没有错误。
您好,我正在创建一个用户控件,用于确定是启用还是禁用主(父)窗体上的特定按钮。
理想情况下,当 UC 上的条件得到满足时,我会从父窗体调用一个方法来设置状态。但那是行不通的。
我怎样才能做到这一点?
主窗体(form_load):
Dim myTSButton As New ToolStripButton
With myTSButton
.Text = ""
.Image = Icons.My.Resources.myIcon.ToBitmap
.Enabled = False
AddHandler .Click, AddressOf myTSButton_Click
.Name = "myTSButton"
tStrip.Items.Add(myTSButton)
End With
UC 将显示一些复选框,选择这些复选框可能会启用或禁用此 myTSButton。
If ConditionsAreMet Then
'Enable the myTSButton on my parent form!
End If
If ConditionsAreMet Then
Dim btn As ToolStripItem = CType(tStrip.Items.Find("myTSButton", True).ElementAt(0), ToolStripItem)
btn.Enabled = True
End If
用 VB2010 测试没有错误。