在form中加入:
button1.Click+=EvenHandle(button1_Click);
然后:
private void button1_Click(object sender,System.EventArgs e)
{
......
}
button1.Click+=EvenHandle(button1_Click);
然后:
private void button1_Click(object sender,System.EventArgs e)
{
......
}
解决方案 »
- docnetbar 子窗体在菜单栏上显示最大最小化按钮
- 编写的Windows Service怎样让系统或者防火墙信任(而不是手动在防火墙中添加信任列表)?
- 关于连接流量计算的问题[有重赏]
- 关于winform中嵌入Excel的问题
- silverlight 中怎样读文件
- 如何把一个网页中的href内容替换掉
- WEB页面中的listbox控件如何写单击事件呀?请高手指点
- 输入用户名和密码,如何实现用户登陆?请给具体代码学习!谢谢!
- 有关sql语句的问题?。。我有点弧度了。。。
- 为什么我使用VS·NET粘贴为HTML代码时,源代码总是自动的被添加了一些其它们的代码
- 怎么实现listview的这个功能啊
- 请教微软专家:还是C#调用COM有关参数传递的问题(焦急等待中)!
this.button1.PerformClick();
这样button1所有的Click事件都会得到响应.例如:private void InitializeComponent()
{
...
this.button1.Click += new System.EventHandler (this.button1_Click);
this.button1.Click += new System.EventHandler(this.button1_Click2);
...
}private void button1_Click(object sender, System.EventArgs e)
{
this.textBox1.Text = "Click!";
}
private void button1_Click2(object sender, System.EventArgs e)
{
this.textBox2.Text = "Click!";
}
private void button2_Click(object sender, System.EventArgs e)
{
this.button1.PerformClick();
}
======================
- 微软全球技术中心本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
======================
{
public class Mother
{
public void Noop()
{
Father father=new Father();
father.myevent(null,null); //illegal
}
} public class Father
{
public event System.EventHandler myevent;
public void Noop()
{
this.myevent(null,null); // correct
}
}
}编译该程序后编译器会报错:The event 'GeneralTest.Father.myevent' can only appear on the left hand side of += or -= (except when used from within the type 'GeneralTest.Father')。编译器报告该错误的原因就是在Father类的外部(即在Mother.Noop()中)直接raise了Father.myevent事件,这是语法规则所不允许的。而在Father.Noop()中触发Father.myevent就是合法的。.NET之所以做这样的规定,原因是如果允许外部类(尤其是子类)任意触发基类的event,会使基类的event的安全无法得到保证。- 微软全球技术中心 acptvc本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。