本文介绍了我可以在form2按钮中调用form1 button1单击事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在form2中调用form1的按钮单击事件吗?

i want to call the form1 button click event in form2 is it possible to call the event click of button?

推荐答案


Form1 f = new Form1();
 f.button1_Click(sender, e);


partial class Form1
{
 Form1()
 {}
 
 protected Form1_Load(object,EventArgs)
 {
  Form2 frm = new Form2(this);
  frm2.Show();
 }

 protected void Button1_Click(object,EventArgs)
 { //Event Body
 }

 public void CallButton1Click()
 {
   Button1_Click(null,null)
 }
}

class Form2
{
 Form1 frm= null;
 Form2()
 {}
 Form2(Form argForm)
 {
   frm = (Form1) argForm
 }

 protected Form2_Load(object,EventArgs)
 {
   frm.CallButton1Click();
 }
}





它会为您工作





it will work for you


这篇关于我可以在form2按钮中调用form1 button1单击事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:50