Skip to content

API ModernFormsNext Application

ProGraMajster edited this page Jun 27, 2026 · 1 revision

ModernFormsNext.Application

Remarks

This class is responsible for starting the UI message loop, tracking open forms, dispatching actions to the UI thread, and shutting down the application.

        Before the main loop starts, the framework backend is initialized automatically
        through `ModernFormsNext.WindowKit.Backend.FrameworkBootstrap`.

Example

`csharp

        var form = new MainForm();
        Application.Run(form);

`

Events

OnExit

Remarks

This event is raised when ModernFormsNext.Application.Exit is called or when the main application loop finishes without the application already being marked as exiting.

Methods

ClosePopups(System.Boolean,System.Boolean)

Parameters

  • closeMenus - true to deactivate the active menu; otherwise, false.
  • closePopups - true to hide the active popup window; otherwise, false.

DoThemeChanged

Remarks

This method iterates through ModernFormsNext.Application.OpenForms and calls each form's theme change handler.

Exit

Remarks

This method marks the application as exiting, raises the ModernFormsNext.Application.OnExit event, and cancels the main loop cancellation token if the application loop is running.

        Calling this method does not forcefully terminate the process. It requests a graceful
        shutdown of the UI loop.

Run(ModernFormsNext.Form)

Parameters

  • mainForm - The main form to show before entering the UI loop.

Remarks

This method ensures that the backend is initialized, shows the specified form, and then starts the UI message loop.

        When the provided form is closed, the application exits automatically.

Example

`csharp

        var mainForm = new MainForm();
        Application.Run(mainForm);

`

Run(ModernFormsNext.WindowKit.ICloseable)

Parameters

  • closable - An object that controls application lifetime and exposes a Closed event.

Remarks

This overload starts the UI message loop without requiring a ModernFormsNext.Form instance. It is useful for advanced hosting scenarios where a custom closeable root object controls the lifetime of the application.

        This method can only be called once during the lifetime of the process.

RunOnUIThread(System.Action)

Parameters

  • action - The action to execute on the UI thread.

Example

`csharp

        Application.RunOnUIThread(() =>
        {
            myForm.Text = "Updated from another thread";
        });

`

Propertys

ActiveMenu

ActivePopupWindow

OpenForms

StartupPath

Remarks

The value is initialized lazily from System.AppContext.BaseDirectory.

ModernFormsNext

Clone this wiki locally