using System;
using System.Windows.Forms;
using System.Drawing;
class ButtonEventFormLocation : Form {
Button MyButton = new Button();
public ButtonEventFormLocation() {
Text = "Respond to a Button";
MyButton = new Button();
MyButton.Text = "Press Here";
MyButton.Location = new Point(100, 200);
// Add button event handler to list.
MyButton.Click += MyButtonClick;
Controls.Add(MyButton);
}
[STAThread]
public static void Main() {
ButtonEventFormLocation skel = new ButtonEventFormLocation();
Application.Run(skel);
}
// Handler for MyButton.
protected void MyButtonClick(object who, EventArgs e) {
if(MyButton.Top == 200)
MyButton.Location = new Point(10, 10);
else
MyButton.Location = new Point(100, 200);
}
}