C# 事件调用
我想在class类里调用Form1窗体的button控件的单击事件,请问要怎么在class类的方法里怎么去写?
------解决方案--------------------最简单的方法,把button事件的代码写成一个静态方法..直接调用
------解决方案--------------------其中一种:
public class Form1
{
.......
......
private void button_Click(object sender,EventArgs e)
{
....
}
public void ClickHandler()
{
button_Click(button,null);
}
}
public class Fuck
{
private Form owner;
public Fuck(Form frm)
{
owner=frm;
}
public void Click()
{
frm.ClickHandler();
}
}
------解决方案--------------------代码忘记格式化了,真难看
public class Form1
{
.......
......
private void button_Click(object sender,EventArgs e)
{
....
}
public void ClickHandler()
{
button_Click(button,null);
}
}
public class Fuck
{
private Form owner;
public Fuck(Form frm)
{
owner=frm;
}
public void Click()
{
frm.ClickHandler();
}
}
------解决方案--------------------button1定义成public的
然后写
(Application.OpenForms["Form1"] as Form1).button1.PreformClick();