WindowsFormsApplicationBase.Startup Event
Occurs when the application starts.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
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 StartupNextInstance and How to: Specify Instancing Behavior for an Application (Visual Basic).
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 (Visual Basic).
You can use the CommandLine property of the e parameter or the 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 |
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 (Visual Basic) |
|
Check if the application started with the string /batch as an argument |
How to: Enable a Batch Mode for Window Forms Applications (Visual Basic) |
Availability by Project Type
|
Project type |
Available |
|
Windows Forms Application |
Yes |
|
Class Library |
No |
|
Console Application |
No |
|
Windows Forms Control Library |
No |
|
Web Control Library |
No |
|
Windows Service |
No |
|
Web Site |
No |
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_Startup( ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs ) Handles Me.Startup ' Get the splash screen. Dim splash As SplashScreen1 = CType(My.Application.SplashScreen, SplashScreen1) ' Display current status information. splash.Status = "Current user: " & My.User.Name 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).
-
SecurityPermission
Controls the ability to add an event handler for this event. Associated enumeration: SecurityPermissionFlag.ControlAppDomain.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.