This documentation is archived and is not being maintained.

WindowsFormsApplicationBase.Startup Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when the application starts.

Namespace: Microsoft.VisualBasic.ApplicationServices
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public event StartupEventHandler Startup
/** @event */
public void add_Startup (StartupEventHandler obj)

/** @event */
public void remove_Startup (StartupEventHandler obj)

JScript supports the use of events, but not the declaration of new ones.

For more detailed information, see the Visual Basic topic My.Application.Startup Event.

A normal (non-single-instance) application raises the Startup event every time it starts. A single-instance application raises the Startup event when it starts only if the application is not already active; otherwise, it raises the StartupNextInstance event. For more information, see My.Application.StartupNextInstance Event and How to: Specify Instancing Behavior for an Application.

This event is part of the Visual Basic Application model. For more information, see Overview of the Visual Basic Application Model.

You can use the Cancel property of the e parameter to control the loading of an application's startup form. When the Cancel property is set to True, the startup form does not start. In that case, your code should call an alternate startup code path. For example, see How to: Enable a Batch Mode for Window Forms Applications.

You can use the CommandLine property of the e parameter or the My.Application.CommandLineArgs Property to access the application's command-line arguments.

The code for the Startup event handler is stored in the ApplicationEvents.vb file, which is hidden by default.

To access the Code Editor window for application events

With a project selected in Solution Explorer, click Properties on the Project menu.

Click the Application tab.

Click the View Application Events button to open the Code Editor.

For more information, see How to: Handle Application Events (Visual Basic).

The following table lists examples of tasks involving the My.Application.Startup event.

To

See

Use the events provided by the Visual Basic Application model to run code

How to: Run Code When the Application Starts or Ends

Check if the application started with the string /batch as an argument

How to: Enable a Batch Mode for Window Forms Applications

This example uses the My.Application.SplashScreen property and the My.Application.Startup event to update the splash screen with status information as the application starts.

Private Sub MyApplication_Shutdown( _
    ByVal sender As Object, _
    ByVal e As System.EventArgs _
) Handles Me.Shutdown
    My.Application.Log.WriteEntry("Application Shut Down.")
End Sub

This example requires that the project have a splash screen named SplashScreen1. The splash screen needs to have property named Status that updates its user interface.

You must enter the code in the Code Editor window for application events. To access this window, follow the instructions from this topic's Remarks section. For more information, see How to: Handle Application Events (Visual Basic).

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Show: