我有三个WinForms .. Form1 Form2和Form3
// Form1 Button
private void btF1_Click(object sender, EventArgs e)
{
new Form3(this).ShowDialog();
}
// Form2按钮
private void btF21_Click(object sender, EventArgs e)
{
new Form3(this).ShowDialog();
}
// Form3
public partial class AjoutDemandeur : Form
{
Form1 _owner;
Form2 _owner2;
public Form3(Form1 owner, Form2 owner2)
{
InitializeComponent();
_owner = owner;
_owner2 = owner2;
}
private void button1_Click(object sender, EventArgs e)
{
_owner.methodForm1(); //call a method from Form1
}
private void button2_Click(object sender, EventArgs e)
{
_owner2.methodForm2(); // call a method from Form2
}
我想将Form1和Form2中的方法调用到Form3中 但问题在于btF1和btF2两个按钮 =>没有给出的参数对应于'Form3.Form3(Form1,Form2)所需的形式参数'owner2' 所以任何解决方案!
答案 0 :(得分:1)
在Form1和Form2中创建事件及其处理程序。现在从Form3中激活那些事件。
答案 1 :(得分:0)
解决了! 我只需要在调用方法
中传递一个null参数// Form1 Button
private void btF1_Click(object sender, EventArgs e)
{
new Form3(this,null).ShowDialog();
}
// Form2按钮
private void btF21_Click(object sender, EventArgs e)
{
new Form3(null,this).ShowDialog();
}