programming-examples/c-sharp/Others/Add control to a window.cs
2019-11-15 12:59:38 +01:00

35 lines
735 B
C#

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());
}
}