Form.TopLevel Property

Definition

Gets or sets a value indicating whether to display the form as a top-level window.

C#
[System.ComponentModel.Browsable(false)]
public bool TopLevel { get; set; }

Property Value

true to display the form as a top-level window; otherwise, false. The default is true.

Attributes

Exceptions

A Multiple-document interface (MDI) parent form must be a top-level window.

Examples

The following example use the Modal property to determine if a form is displayed as a modal form. If it is not the FormBorderStyle and TopLevel properties are changed to make the form non-top-level form with a tool window border.

C#
private void ShowMyNonModalForm()
{
    Form myForm = new Form();
    myForm.Text = "My Form";
    myForm.SetBounds(10,10,200,200);

    myForm.Show();
    // Determine if the form is modal.
    if (!myForm.Modal)
    {
        // Change borderstyle and make it not a top level window.
        myForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
        myForm.TopLevel = false;
    }
}

Remarks

A top-level form is a window that has no parent form, or whose parent form is the desktop window. Top-level windows are typically used as the main form in an application.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also