Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 从父窗体调用方法的用户控件_Vb.net_Winforms_User Controls - Fatal编程技术网

Vb.net 从父窗体调用方法的用户控件

Vb.net 从父窗体调用方法的用户控件,vb.net,winforms,user-controls,Vb.net,Winforms,User Controls,Hi am正在创建一个用户控件,该控件将确定主(父)窗体上的特定按钮是启用还是禁用 理想情况下,当UC上的条件满足时,我将从父窗体调用一个方法来设置状态。但这不起作用 我怎样才能做到这一点 主模板(模板荷载): UC将显示一些复选框,其选择可能启用或禁用此myTSButton If ConditionsAreMet Then 'Enable the myTSButton on my parent form! End If 使用VB2010进行测试,没有错误。Form1.button.ena

Hi am正在创建一个用户控件,该控件将确定主(父)窗体上的特定按钮是启用还是禁用

理想情况下,当UC上的条件满足时,我将从父窗体调用一个方法来设置状态。但这不起作用

我怎样才能做到这一点

主模板(模板荷载):

UC将显示一些复选框,其选择可能启用或禁用此myTSButton

If ConditionsAreMet Then
  'Enable the myTSButton on my parent form!
End If

使用VB2010进行测试,没有错误。

Form1.button.enabled=True?哦,忘了提到。。。该按钮实际上是在“Form1”上动态创建的toolstripbutton,因此我无法这样访问它。请显示一些代码…一个简单的解决方案是在usercontrol中添加一个eventhandler,每次状态更改时都会调用它。然后主窗体可以将自己的处理程序添加到事件中,从而更新按钮。我认为这就是方法。我在UC中声明了一个事件,在ConditionsRemet时引发了它,并在主窗体上创建了一个名为“Protected Sub enableButton()Handles myUC1.enableButton”的方法—这返回了一些错误:使用“As”子句声明的事件必须具有委托类型
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