在form中加入:
   button1.Click+=EvenHandle(button1_Click);
然后:
  private void button1_Click(object sender,System.EventArgs e)
  {
   ......
    
   }

解决方案 »

  1.   

    感谢您使用微软产品。您可以调用PerformClick方法来触发Click事件:
    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))。
    ======================
      

  2.   

    简单的说,只能通过Button.PerformClick()函数来编程触发Button.Click事件,.NET不允许直接通过button1.Click(this,e)来触发该事件。.NET中一个类的所有通过event关键字定义的事件(无论是public或protected),都只能在这个类本身的method里面出发(raise)。在类的外部(无论是外部函数还是子类),都不允许直接通过执行Delegate的方法来出发事件。以下的例子代码可以加以说明:namespace GeneralTest
    {
    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))。