如何从其他winform调用按钮? [英] How to call a button from other winform ?

查看:207
本文介绍了如何从其他winform调用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种形式(Form1和Form2)

我想在Form2上单击按钮时从Form1调用一个按钮

感谢重播,

i have two forms ( Form1 & Form2 )
I want to call a button from Form1 when clicking a button on Form2
Thanks for the replay,,

推荐答案

嗨Peter,



单击Form2上的按钮时调用Form1中的Button我知道你想要的要调用事件,请单击form1右侧的按钮?

如果是这种情况,您必须首先转到表单1的源代码并使方法button1_click(...)public



例如:



Hi Peter,

by calling Button in Form1 when clicking a button on Form2 I understand that you want to invoke the event click on the button in the form1 right?
If that is the case you must first go to the source code of the Form 1 and make the method button1_click(...) public

e.g.:

public void button1_Click(object sender, EventArgs e)
{

}





然后在form2按钮单击事件中,您可以在form1中调用方法





Then in the form2 button click event you can call the method in the form1

public void button1_Click(object sender, EventArgs e)
{
    Form1 frm = new Form1();
    frm.button1_Click(sender, e);
}





希望有所帮助。



Hope that helps.


有很多如何实现这一目标。也许最简单的方法是将form1 button1_click公开,然后只需在form2中按下button_click,调用form1.button1_Click(null,null);
there are many ways to archieve this. Maybe the easiest one is making the form1 button1_click public and then just in form2 button_click call form1.button1_Click(null, null);


看看下面的讨论,它可能会有所帮助:

http://stackoverflow.com/问题/ 20730697 /听取自定义事件 - 从不同的形式发起的事件 [ ^ ]
Have a look on below discussion, it may help:
http://stackoverflow.com/questions/20730697/listening-for-a-custom-event-fired-from-different-winform[^]


这篇关于如何从其他winform调用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆