c#eventArgs形成事件

时间:2017-03-10 10:39:30

标签: c# events types custom-events

我有多种形式,设计相同,如:

In Form1{
Form2 = new Formtoopen();
Form2.Resize += new EventHandler(Form2_Resize);
Form2.FormClosing +=new FormClosingEventHandler(Form2_FormClosing);
}

然后是事件:

In Form1{
protected virtual void Fly_Form2_Closing(object sender, FormClosingEventArgs e)
{
   if (e.CloseReason == CloseReason.UserClosing)
   {
      e.Cancel = true;
      Fly_Form2.Hide();
   }
}

protected virtual void Fly_Form2_Visiblechanged(object sender, EventArgs e)
{
   //some code
}
}

我想在EventArgs中添加Form2 Type,从现在开始是空的。 我认为这会使我的代码更简单,因为我有多个Form共享相同的代码。

我怎么能这样做?我想过事件自定义参数方式,但我不确定Type ...

你能帮帮我吗?

由于

1 个答案:

答案 0 :(得分:0)

这是有用的:

 In Form1{
Form2 = new Formtoopen();
Form3 = new Formdata();
Form2.FormClosing +=new FormClosingEventHandler(Form_FormClosing);
Form3.FormClosing += new FormClosingEventHandler(Form_FormClosing);
}

 In Form1{
protected virtual void Form_Closing(object sender, FormClosingEventArgs  e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
  e.Cancel = true;
  ((Form)sender).Hide();
}
}

从对象发件人检索带有强制转换表单的发件人。

非常感谢M.Passant!