This topic has not yet been rated - Rate this topic

WindowsFormsApplicationBase Class

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

System.Object
  Microsoft.VisualBasic.ApplicationServices.ApplicationBase
    Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase
      Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase

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.

  Name Description
Public method WindowsFormsApplicationBase() Initializes a new instance of the WindowsFormsApplicationBase class.
Public method WindowsFormsApplicationBase(AuthenticationMode) Initializes a new instance of the WindowsFormsApplicationBase class with the specified authentication mode.
Top
  Name Description
Public property ApplicationContext Gets the ApplicationContext object for the current thread of a Windows Forms application.
Public property CommandLineArgs Gets a collection containing the command-line arguments as strings for the current application. (Inherited from ConsoleApplicationBase.)
Public property Culture Gets the culture that the current thread uses for string manipulation and string formatting. (Inherited from ApplicationBase.)
Public property Deployment Gets 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 property EnableVisualStyles Determines whether this application will use the Windows XP styles for windows, controls, and so on.
Public property Info Gets 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 property InternalCommandLine Sets the values to use as the current application's command-line arguments. (Inherited from ConsoleApplicationBase.)
Public property IsNetworkDeployed Gets a Boolean that represents whether the application was deployed from a network using ClickOnce. (Inherited from ConsoleApplicationBase.)
Protected property IsSingleInstance Determines whether this application is a single-instance application.
Public property Log Gets an object that provides properties and methods for writing event and exception information to the application's log listeners. (Inherited from ApplicationBase.)
Protected property MainForm Gets or sets the main form for this application.
Public property MinimumSplashScreenDisplayTime Determines the minimum length of time, in milliseconds, for which the splash screen is displayed.
Public property OpenForms Gets a collection of all the application's open forms.
Public property SaveMySettingsOnExit Determines whether the application saves the user settings on exit.
Protected property ShutdownStyle Determines what happens when the application's main form closes.
Public property SplashScreen Gets or sets the splash screen for this application.
Public property UICulture Gets the culture that the current thread uses for retrieving culture-specific resources. (Inherited from ApplicationBase.)
Protected property Static member UseCompatibleTextRendering When overridden in a derived class, this property allows a designer to specify the default text rendering engine for the application's forms.
Top
  Name Description
Public method ChangeCulture Changes the culture used by the current thread for string manipulation and for string formatting. (Inherited from ApplicationBase.)
Public method ChangeUICulture Changes the culture that the current thread uses for retrieving culture-specific resources. (Inherited from ApplicationBase.)
Public method DoEvents Processes all Windows messages currently in the message queue.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnvironmentVariable Returns the value of the specified environment variable. (Inherited from ApplicationBase.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method HideSplashScreen Hides the application's splash screen.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnCreateMainForm When overridden in a derived class, allows a designer to emit code that configures the splash screen and main form.
Protected method OnCreateSplashScreen When overridden in a derived class, allows a designer to emit code that initializes the splash screen.
Protected method OnInitialize Sets 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 method OnRun Provides the starting point for when the main application is ready to start running, after the initialization is done.
Protected method OnShutdown When overridden in a derived class, allows for code to run when the application shuts down.
Protected method OnStartup When overridden in a derived class, allows for code to run when the application starts.
Protected method OnStartupNextInstance When overridden in a derived class, allows for code to run when a subsequent instance of a single-instance application starts.
Protected method OnUnhandledException When overridden in a derived class, allows for code to run when an unhandled exception occurs in the application.
Public method Run Sets up and starts the Visual Basic Application model.
Protected method ShowSplashScreen Determines if the application has a splash screen defined, and if it does, displays it.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public event NetworkAvailabilityChanged Occurs when the network availability changes.
Public event Shutdown Occurs when the application shuts down.
Public event Startup Occurs when the application starts.
Public event StartupNextInstance Occurs when attempting to start a single-instance application and the application is already active.
Public event UnhandledException Occurs when the application encounters an unhandled exception.
Top

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.

Note Note

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

    Try
        For Each f As Form In My.Application.OpenForms
            If Not f.InvokeRequired Then
                ' Can access the form directly.
                formTitles.Add(f.Text)
            End If
        Next
    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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ