how to handle programmatically added button events? c#

前端 未结 6 1746
悲哀的现实
悲哀的现实 2020-12-03 07:39

I\'m making a windows forms application using C#. I add buttons and other controls programmatically at run time. I\'d like to know how to handle those buttons\' click events

6条回答
  •  清歌不尽
    2020-12-03 08:03

    Try the following

    Button b1 = CreateMyButton();
    b1.Click += new EventHandler(this.MyButtonHandler);
    ...
    void MyButtonHandler(object sender, EventArgs e) {
      ...
    }
    

提交回复
热议问题