// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Drawing; using System.Windows.Forms; namespace E { public class MainForm : Form { private Button button1; private Button button2; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { button1 = new Button(); button2 = new Button(); SuspendLayout(); button1.Location = new Point(50, 50); button1.Size = new Size(75, 25); button1.Text = "button1"; button1.Click += new EventHandler(ButtonClick); button2.Location = new Point(150, 50); button2.Size = new Size(75, 25); button2.Text = "button2"; button2.Click += new EventHandler(ButtonClick); ClientSize = new Size(300, 150); Controls.Add(button1); Controls.Add(button2); Text = "MainForm"; ResumeLayout(false); } private void ButtonClick(object sender, EventArgs e) { if(sender == button1) { MessageBox.Show("Button 1"); } else if(sender == button2) { MessageBox.Show("Button 2"); } } } }