Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
C# 将事件从一个窗体发送到另一个窗体_C#_User Interface - Fatal编程技术网

C# 将事件从一个窗体发送到另一个窗体

C# 将事件从一个窗体发送到另一个窗体,c#,user-interface,C#,User Interface,我真的很难解决这个看似简单的问题: 我有一个表单(子表单)和一个按钮,单击该按钮时,应将文本框的焦点设置在另一个表单(父表单)上 我尝试使用一些代码,如下所示:我的问题是这是正确的方法吗? 如果是,如何解决此错误消息 无法将类型“System.EventHandler”隐式转换为“ChildForm.SomeEventHandler” 您需要从更改作业 child.SomeEvent += new EventHandler(this.HandleSomeEvent); 到 编辑1: 它非常适合

我真的很难解决这个看似简单的问题: 我有一个表单(子表单)和一个按钮,单击该按钮时,应将文本框的焦点设置在另一个表单(父表单)上

我尝试使用一些代码,如下所示:我的问题是这是正确的方法吗? 如果是,如何解决此错误消息

无法将类型“System.EventHandler”隐式转换为“ChildForm.SomeEventHandler”


您需要从更改作业

child.SomeEvent += new EventHandler(this.HandleSomeEvent);

编辑1: 它非常适合在子窗体中发生操作时处理父窗体中的事件。虽然它看起来不是线程安全的


请看

谢谢Abhinav。但是,当我更改为:child.SomeEvent+=newsomeeventhandler(this.HandleSomeEvent);感谢我尝试更改为:child.SomeEvent+=newsomeeventhandler(this.HandleSomeEvent);另一条消息显示,找不到SomeEventHandler的类型或命名空间名称或缺少引用。我已使用完全限定名更新了答案。Abhinav先生,我需要您帮助解决上述问题。为什么在您建议的更改后我会收到此错误消息:“找不到SomeEventHandler的类型或命名空间名称或缺少引用”
child.SomeEvent += new EventHandler(this.HandleSomeEvent);
child.SomeEvent += new ChildForm.SomeEventHandler(this.HandleSomeEvent);