本文介绍了从另一个窗体调用一个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试调用从另一种形式的方法。我尝试:
I try to call a method from another form. My try:
public partial class newLedPopUp : Form
{
Form1 back = new Form1();
back.output();
Close();
}
和
public partial class Form1 : Form
{
newLedPopUp popup = new newLedPopUp();
public void output()
{
button3_Click(null, null);
}
}
有人可以帮我吗?我真的找不到我的错误,我一直在寻找了很长的时间。
Can somebody help me? I really can't find my error and I've been looking for a very long time.
推荐答案
而不是创建一个新的窗体的实例,你可能需要已经打开窗体的实例,并从那里调用该方法。你可以试试:
Instead of creating an instance of a new Form, you probably need an instance of already opened form and call the method from there. You can try:
if (System.Windows.Forms.Application.OpenForms["yourForm"] != null)
{
(System.Windows.Forms.Application.OpenForms["yourForm"] as Form1).Output();
}
再加上你可以(NULL,NULL)在输出
方法,通过将$替换调用 button3_Click在一个单独的方法事件的C $ c和然后调用对你的按钮点击事件或公共输出方式
plus you can replace calling the button3_Click(null,null)
in your Output
method, by placing the code of the event in a separate method and then calling that method against your button click event or your public output method
这篇关于从另一个窗体调用一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!