class CSharp1Syntax
{
static void LogPlainEvent(object sender, EventArgs e) //点击触发
{
Console.WriteLine ("LogPlain");
}
static void LogKeyEvent(object sender, KeyPressEventArgs e) //空格键触发
{
Console.WriteLine ("LogKey");
}
static void LogMouseEvent(object sender, MouseEventArgs e) //鼠标触发
{
Console.WriteLine ("LogMouse");
}
static void Main()
{
Button button = new Button();
button.Text = "Click me"; //按钮的文本 变成 Click me
button.Click += new EventHandler(LogPlainEvent); //点击触发
button.KeyPress += new KeyPressEventHandler(LogKeyEvent);
button.MouseClick += new MouseEventHandler(LogMouseEvent); //增加LogMouse
Form form = new Form(); //新建窗体
form.AutoSize = true;
form.Controls.Add(button);
Application.Run(form);
}
}
空格 LogKeyEvent
回车 LogPlainEvent
鼠标点击 LogPlainEvent LogMouseEvent
输出结果不定 看按空格 还是回车 还是鼠标点击
LogPlain
LogMouse