C#里如何让一个事件函数动态的让按钮点击触发。比如一个事件函数可以让多个按钮触发,而这些按钮是一些按钮数组。

解决方案 »

  1.   

    foreach(Button B in Button[])
    {
       B.Click += new System.EventHandler(this.B_Login_Click);
       if(B.CommandArgument=="測試")
       {
            //自行添加處理的代碼
       }
    }
      

  2.   

    foreach(Button B in new Button[]{this.B_Login,this.Button1})
    {
       B.Click += new System.EventHandler(this.B_Login_Click);
       if(B.CommandArgument=="測試")
       {
            //自行添加處理的代碼
       }
    }
      

  3.   

    类似
    this.cmd_Sort.Click += new System.EventHandler(this.cmd_Sort_Click);
    this.cmd_Random.Click += new System.EventHandler(this.cmd_Random_Click);
    this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);

    这样
      

  4.   

    delegate 就是你需要的目的!!!
    你肯定有MSDN的,赶紧补回来哦~~~
      

  5.   

    我就不明白了,关键不是按钮点击被触发,而是按钮触发后要做的事情先不管这个。有个Button.PerformClick 方法,不知道会不会有帮助。
      

  6.   

    看了你后面的说明,我不知道理解正确与否。你可以用datagrid控件显示数据库的内容,然后添加编辑、修改、删除命令按钮,它会为每一行添加按钮啊,你直接写一个按钮处理函数代码就行吧。