Mega Code Archive

 
Categories / C# Tutorial / WPF
 

Inherit Application class and override OnStartup

using System; using System.Windows; using System.Windows.Input; class MyApplication : Application {     protected override void OnStartup(StartupEventArgs args)     {         base.OnStartup(args);         MyWindow win = new MyWindow();         win.Show();     } } class MyWindow : Window {     public MyWindow()     {         Title = "title";     }     protected override void OnMouseDown(MouseButtonEventArgs args)     {         base.OnMouseDown(args);         string strMessage = args.ChangedButton.ToString();         MessageBox.Show(strMessage, Title);     } } class MainClass {     [STAThread]     public static void Main()     {         MyApplication app = new MyApplication();         app.Run();     } }