[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Collapse]Build an Application
  [Expand]Choose Application UI
  [Expand]Printing and Exporting
  [Expand]WinForms MVVM
  [Expand]Skins
  [Expand]Localization
  [Expand]Right-to-Left Layout
   Redistribution and Deployment
   How to: Perform Actions On Application Startup
 [Expand]Controls and Libraries
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Perform Actions On Application Startup

You may need to perform certain actions in code before opening the main application form. For instance, to enable DirectX Hardware Acceleration you need to call the WindowsFormsSettings.ForceDirectXPaint method before the main application form is created.

This topic shows where you can place the application initialization code when developing projects in C# and Visual Basic. If you are a Visual Basic developer, you can choose one of the methods listed below depending on your requirements.

Expanded C# Example

For a C# project, locate the Program.cs file in the Solution Explorer. This file contains the static void Main() procedure, in which you can add custom code before the Application.Run method call.

Expanded Visual Basic Example - Method 1

With this approach, you create the Main function and set it as the application's entry point.

  1. Right-click your project in the Solution Explorer and select Properties in the context menu.
  2. Uncheck Enable application framework and then set Startup object to Sub Main in the Application tab.

  3. Switch to the your main form's code editor and manually add the following Shared Sub Main procedure to your form class:

  4. Insert the code to be executed before the Application.Run method call.

Expanded Visual Basic Example - Method 2

With this approach, you subscribe to the application's Startup event to perform custom actions.

  1. Right-click your project in the Solution Explorer and select Properties in the context menu.
  2. Click the View Application Events button in the Application tab.

  3. Subscribe to the Startup event in the ApplicationEvents.vb file that opens.

  4. Insert the code to be executed in the generated Startup event handler.

Is this topic helpful?​​​​​​​