Button btn = new Button();
btn.Text = "Sample Button";
btn.Left = 100;
btn.Top = 100;
this.Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
btn.MouseHover += new EventHandler(btn_MouseHover);
Here we are using EventHandler - a predefined delegate that specifically represents an event handler method for an event that does not generate data.
The code will link the event handler btn_Click with the click event
btn.Click += new EventHandler(btn_Click);
void btn_Click(object sender, EventArgs e)
{
MessageBox.Show("Clicked...");
}
No comments:
Post a Comment