Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

c# - Add events to controls added dynamically

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? also can some one refer a C# book to me which has covered well all topics in winform? thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
// 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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...