EventHandler :
public delegate void EventHandler(object who, EventArgs args)
, , who, , , args.
args , EventArgs. , .
, . .
// listing 3
// .
Using System;
Using System.Windows.Forms;
Using System.Drawing;
class ButtonForm: Form
{
Button MyButton = new Button(); // .
public ButtonForm() //
{
Text = " "; //
MyButton.Text = ""; //
MyButton.Location = new Point(100, 200); // .
// .
MyButton.Click += new EventHandler(MyButtonClick);
Controls.Add(MyButton); // .
}
[STAThread]
Public static void Main()
{
ButtonForm skel = new ButtonForm();
Application.Run(skel);
}
// 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);
}
}
:
// 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);
}
MyButtonClick () , EventHandler, , Click.
, protected. , , , .
.
( ):
public int Top { get; set; }
public int Bottom { get; }
public int Left { get; set; }
public int Right { get; }
, Left, Bottom Right, . ( Width Height.)
|
|
, , , , 200, : 10, 10. 100, 200. .
MyButtonClick () , , Click. ButtonForm :
MyButton.Click += new EventHandler(MyButtonClick);
MyButtonClick ().