using System;
using System.Windows;
using System.Windows.Input;
namespace BrawDraw.Com.WPF.HandleEvents
{
class HandleAnEvent
{
[STAThread]
public static void Main()
{
Application app = new Application();
Window win = new Window();
win.Title = "Handle An Event";
win.MouseDown += WindowOnMouseDown;
win.KeyUp += WindowOnKeyUp;
app.Run(win);
}
static void WindowOnMouseDown(object sender, MouseButtonEventArgs args)
{
Window win = sender as Window;
string msg =
string.Format("在位置({1})处按了{0}鼠标按钮",
args.ChangedButton, args.GetPosition(win));
MessageBox.Show(msg, win.Title);
}
static void WindowOnKeyUp(object sender, KeyEventArgs args)
{
Window win = sender as Window;
if (args.Key != Key.Return)
{
string msg = string.Format("检测到您按了{0}键。", args.Key.ToString());
MessageBox.Show(msg, win.Title);
}
}
}
}