/***************WPF入门*************** * 环境:VS2008 * 添加引用:PresentationCore、PresentationFramework、WindowsBase ******************************/ using System; using System.Windows; using System.Windows.Input; namespace WpfApp { class MainFrm { [STAThread] public static void Main() { Window win = new Window(); win.Title = "hello wpf"; win.Show(); win.MouseDown += WindowOnMouseDown; Application app = new Application(); app.Run(); } static void WindowOnMouseDown(object sender, MouseButtonEventArgs args) { Window win = sender as Window;//公司规范,引用类型用此法转换。 string strMessage = string.Format("window clicked with {0} button at point ({1})" , args.ChangedButton, args.GetPosition(win)); MessageBox.Show(strMessage, win.Title); } } }