[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Collapse]Forms and User Controls
    XtraForm
    Ribbon Form
    Tabbed Form
    Fluent Design Form
    XtraUserControl
    Form Assistant
    Taskbar Assistant
   [Expand]Splash Screen Manager
   [Expand]Adorner UI Manager
   [Collapse]Examples
     How to: Add New XtraForm, RibbonForm and XtraUserControl to Your Project
     How to: Convert Form and UserControl Types
     How to: Perform Actions On Application Startup
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [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]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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?​​​​​​​