Add events to controls added dynamically

前端 未结 2 790
后悔当初
后悔当初 2020-11-30 07:59

I am working on winform app. and I have added some controls dynamicaly eg. Button now i want to add an event to that created button, how can i perform this? als

2条回答
  •  佛祖请我去吃肉
    2020-11-30 08:34

    // create some dynamic button
    Button b = new Button();
    // assign some event to it
    b.Click += (sender, e) => 
    {
        MessageBox.Show("the button was clicked");
    };
    // add the button to the form
    Controls.Add(b);
    

提交回复
热议问题