Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


CSharp Programming

CSharp > Code Examples

Add control to a window

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Add control to a window using System; using System.Windows.Forms; public class MyForm : Form{ void btn1_onclick(object sender, EventArgs e) { Text = "Sender: " + sender.ToString() + " - Event: " + e.ToString(); } void btn1_onclick2(object sender, EventArgs e){ Console.WriteLine(String.Format("Sender: {0} - Event: {1}", sender.ToString(), e.ToString())); } public MyForm() { Text = "I am Superman"; Button btn1 = new Button(); btn1.Text = "Click Me"; this.Controls.Add(btn1); btn1.Click += new EventHandler(btn1_onclick); btn1.Click += new EventHandler(btn1_onclick2); } public static void Main() { Application.Run(new MyForm()); } }