This documentation is archived and is not being maintained.

WindowsFormsApplicationBase Class

Provides properties, methods, and events related to the current application.

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

[HostProtectionAttribute(SecurityAction.LinkDemand, Resources = HostProtectionResource.ExternalProcessMgmt)]
public class WindowsFormsApplicationBase : ConsoleApplicationBase

The WindowsFormsApplicationBase type exposes the following members.

Public methodWindowsFormsApplicationBase()Initializes a new instance of the WindowsFormsApplicationBase class.
Public methodWindowsFormsApplicationBase(AuthenticationMode)Initializes a new instance of the WindowsFormsApplicationBase class with the specified authentication mode.

Public propertyApplicationContextGets the ApplicationContext object for the current thread of a Windows Forms application.
Public propertyCommandLineArgsGets a collection containing the command-line arguments as strings for the current application. (Inherited from ConsoleApplicationBase.)
Public propertyCultureGets the culture that the current thread uses for string manipulation and string formatting. (Inherited from ApplicationBase.)
Public propertyDeploymentGets the current application's ClickOnce deployment object, which provides support for updating the current deployment programmatically and support for the on-demand download of files. (Inherited from ConsoleApplicationBase.)
Protected propertyEnableVisualStylesDetermines whether this application will use the Windows XP styles for windows, controls, and so on.
Public propertyInfoGets an object that provides properties for getting information about the application's assembly, such as the version number, description, and so on. (Inherited from ApplicationBase.)
Protected propertyInternalCommandLineSets the values to use as the current application's command-line arguments. (Inherited from ConsoleApplicationBase.)
Public propertyIsNetworkDeployedGets a Boolean that represents whether the application was deployed from a network using ClickOnce. (Inherited from ConsoleApplicationBase.)
Protected propertyIsSingleInstanceDetermines whether this application is a single-instance application.
Public propertyLogGets an object that provides properties and methods for writing event and exception information to the application's log listeners. (Inherited from ApplicationBase.)
Protected propertyMainFormGets or sets the main form for this application.
Public propertyMinimumSplashScreenDisplayTimeDetermines the minimum length of time, in milliseconds, for which the splash screen is displayed.
Public propertyOpenFormsGets a collection of all the application's open forms.
Public propertySaveMySettingsOnExitDetermines whether the application saves the user settings on exit.
Protected propertyShutdownStyleDetermines what happens when the application's main form closes.
Public propertySplashScreenGets or sets the splash screen for this application.
Public propertyUICultureGets the culture that the current thread uses for retrieving culture-specific resources. (Inherited from ApplicationBase.)
Protected propertyStatic memberUseCompatibleTextRenderingWhen overridden in a derived class, this property allows a designer to specify the default text rendering engine for the application's forms.

Public methodChangeCultureChanges the culture used by the current thread for string manipulation and for string formatting. (Inherited from ApplicationBase.)
Public methodChangeUICultureChanges the culture that the current thread uses for retrieving culture-specific resources. (Inherited from ApplicationBase.)
Public methodDoEventsProcesses all Windows messages currently in the message queue.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnvironmentVariableReturns the value of the specified environment variable. (Inherited from ApplicationBase.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodHideSplashScreenHides the application's splash screen.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnCreateMainFormWhen overridden in a derived class, allows a designer to emit code that configures the splash screen and main form.
Protected methodOnCreateSplashScreenWhen overridden in a derived class, allows a designer to emit code that initializes the splash screen.
Protected methodOnInitializeSets the visual styles, text display styles, and current principal for the main application thread (if the application uses Windows authentication), and initializes the splash screen, if defined.
Protected methodOnRunProvides the starting point for when the main application is ready to start running, after the initialization is done.
Protected methodOnShutdownWhen overridden in a derived class, allows for code to run when the application shuts down.
Protected methodOnStartupWhen overridden in a derived class, allows for code to run when the application starts.
Protected methodOnStartupNextInstanceWhen overridden in a derived class, allows for code to run when a subsequent instance of a single-instance application starts.
Protected methodOnUnhandledExceptionWhen overridden in a derived class, allows for code to run when an unhandled exception occurs in the application.
Public methodRunSets up and starts the Visual Basic Application model.
Protected methodShowSplashScreenDetermines if the application has a splash screen defined, and if it does, displays it.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public eventNetworkAvailabilityChangedOccurs when the network availability changes.
Public eventShutdownOccurs when the application shuts down.
Public eventStartupOccurs when the application starts.
Public eventStartupNextInstanceOccurs when attempting to start a single-instance application and the application is already active.
Public eventUnhandledExceptionOccurs when the application encounters an unhandled exception.

The properties exposed by the My.Application object return data that is associated only with the current application or DLL. No system-level information can be altered with My.Application.

The My.Application object consists of the following classes:

  • ApplicationBase provides members that are available in all projects.

  • WindowsFormsApplicationBase provides members that are available in Windows Forms applications.

  • ConsoleApplicationBase provides members that are available in console applications.


The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Resources. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

This example uses a loop to iterate through the application's open forms, selects the forms that can be accessed directly by the current thread, and displays their titles in a ListBox control. For information about how to access the open forms, see How to: Access All Open Forms of an Application (Visual Basic).

Private Sub GetOpenFormTitles()
    Dim formTitles As New Collection

        For Each f As Form In My.Application.OpenForms
            If Not f.InvokeRequired Then
                ' Can access the form directly.
            End If
    Catch ex As Exception
        formTitles.Add("Error: " & ex.Message)
    End Try

    Form1.ListBox1.DataSource = formTitles
End Sub

This example requires that your Windows Forms application have a form named Form1 that contains a list box named ListBox1.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.