Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Startup Code in a Windows Presentation Form Application

Tags:

vb.net

wpf

I'm working on a program that requires a file be loaded on program startup. I have seperate code for loading the file, but I've been using some basic methods to try and figure out a way to run code on the startup of a Windows Presentation Form Application. At the moment, I'm just trying to run a MsgBox function on the startup of this application. But I can't figure out how to do so.

like image 461
emufossum13 Avatar asked Dec 09 '22 13:12

emufossum13


1 Answers

From the fine manual:

Application.Startup Event

Occurs when the Run method of the Application object is called.

Example XAML:

<Application
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.App"
  Startup="App_Startup" />

Example C#:

using System.Windows; // Application, StartupEventArgs, WindowState

namespace SDKSample
{
    public partial class App : Application
    {
        void App_Startup(object sender, StartupEventArgs e)
        {
            // Application is running 
            // Process command line args 
            bool startMinimized = false;
            for (int i = 0; i != e.Args.Length; ++i)
            {
                if (e.Args[i] == "/StartMinimized")
                {
                    startMinimized = true;
                }
            }

            // Create main application window, starting minimized if specified
            MainWindow mainWindow = new MainWindow();
            if (startMinimized)
            {
                mainWindow.WindowState = WindowState.Minimized;
            }
            mainWindow.Show();
        }
    }
}
like image 143
ta.speot.is Avatar answered Dec 11 '22 08:12

ta.speot.is