New to Telerik UI for WinForms? Download free 30-day trial

Close Application after Closing All RadTabbedForms


Product Version Product Author
2020.2.616 RadTabbedForm for WinForms Desislava Yordanova


RadTabbedForm allows you to display tabs in the title bar, just like in most modern Web browsers. You can pin the tabs or reorder them via drag drop. You can open any tab in a standalone window as well. Thus, by dragging a tab outside the title bar, you will generate another opened form.

However, in case you have multiple windows (forms) opened, each of which can be closed separately via the close button, closing the main window (form) will close the rest of the available forms as well.

A common requirement is to keep the application running until the last form is closed. Although, this scenario is more like a general-programming question, this article is intended to show how to handle it and keep the application running even in case of closing the main form.


After some research, the following thread seems to be quite useful on this topic and provide different approaches: Close a windows form without exiting the entire application

Usually, the Program file has the following default code:


Application.Run(new RadTabbedForm1());

Application.Run(New RadTabbedForm1()) 

For VB.NET projects, you can refer to the following thread explaining how to simulate a Program.vb file: What is the equivalent of Program.cs in VB.NET


When your application starts, the first thing it does is to create a new form of whichever form is your main form and then run it. The application will quit when that form is closed. The following code snippet demonstrates how to avoid closing the application when the main form is closed:

static class Program
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
        var main_form = new RadTabbedForm1();

        //comment this code line
        //Application.Run(new RadTabbedForm1());

Public Class RadTabbedForm1
    Shared Sub Main()
        Dim main_form = New RadTabbedForm1()
    End Sub
End Class

Then, you can call Application.Exit when the last opened form is being closed:

    public RadTabbedForm1()

        this.AllowAero = false;

        this.FormClosed += RadTabbedForm1_FormClosed;
        this.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating += ItemDragService_TabbedFormCreating;

    private void RadTabbedForm1_FormClosed(object sender, FormClosedEventArgs e)

    private void ItemDragService_TabbedFormCreating(object sender, TabbedFormCreatingEventArgs e)
        e.TabbedForm.FormClosed += TabbedForm_FormClosed;
        e.TabbedForm.TabbedFormControlCreating += TabbedForm_TabbedFormControlCreating;

    private void TabbedForm_TabbedFormControlCreating(object sender, TabbedFormControlCreatingEventArgs e)
        e.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating += ItemDragService_TabbedFormCreating;

    private void TabbedForm_FormClosed(object sender, FormClosedEventArgs e)

    private void CloseApplicationIfLast()
        if (Application.OpenForms.Count == 0)

Public Sub New()
    Me.AllowAero = False
    AddHandler Me.FormClosed, AddressOf RadTabbedForm1_FormClosed
    AddHandler Me.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating, AddressOf ItemDragService_TabbedFormCreating
End Sub

Private Sub RadTabbedForm1_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
End Sub

Private Sub ItemDragService_TabbedFormCreating(ByVal sender As Object, ByVal e As TabbedFormCreatingEventArgs)
    AddHandler e.TabbedForm.FormClosed, AddressOf TabbedForm_FormClosed
    AddHandler e.TabbedForm.TabbedFormControlCreating, AddressOf TabbedForm_TabbedFormControlCreating
End Sub

Private Sub TabbedForm_TabbedFormControlCreating(ByVal sender As Object, ByVal e As TabbedFormControlCreatingEventArgs)
    AddHandler e.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating, AddressOf ItemDragService_TabbedFormCreating
End Sub

Private Sub TabbedForm_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
End Sub

Private Sub CloseApplicationIfLast()
    If Application.OpenForms.Count = 0 Then
    End If
End Sub

See Also

In this article