# Modal and Modeless Windows

## Content

Dialog boxes are commonly used in applications to retrieve input from the user. In some applications a dialog box is used to prompt the user for input and once the application retrieves the input the dialog box is automatically closed or destroyed.

On the other hand, some applications use dialog boxes to display information while the user works in other windows. For example, when you check spelling in Microsoft Word a dialog box remains open so you can go through and edit your text in the document while the spell checker looks for the next misspelled word. To support the different ways applications use dialog boxes, [C1Window](/componentone/api/wpf/online-basiclibrary/dotnet-framework-api/C1.WPF.4.6.2/C1.WPF.C1Window.html) supports two different types of dialog windows: **modal** and **modeless** dialog windows.

### Modal Windows

A modal dialog window is a child window that must be closed before the user can continue working on the current application. Typically modal dialog windows either take control of the entire system or application displaying them until they are closed. For example, you can use a modal dialog window to retrieve login information from a user before the user can continue working on an application. Modal windows are useful in presenting important information or requiring user interaction.

You can show the **C1Window** control as a modal dialog box using the [ShowModal](/componentone/api/wpf/online-basiclibrary/dotnet-framework-api/C1.WPF.4.6.2/C1.WPF.C1Window.ShowModal.html) method:

```vbnet
'The Show method is seen here in an If...Then...Else statement.
If showModal Then
        wnd.ShowModal()
    Else
        wnd.Show()
    End If
```

```csharp
//The Show method is seen here in an if...else statement.
if (showModal)
      wnd.ShowModal();
    else
      wnd.Show();
```

**Setting the Modal Background Color**

You can customize the color of your modal background using the [ModalBackground](/componentone/api/wpf/online-basiclibrary/dotnet-framework-api/C1.WPF.4.6.2/C1.WPF.C1Window.ModalBackground.html) property:

1. Once you complete the **Windows Quick Start**, switch to Code view and locate the code for the **Button2\_Click** event.
2. Edit the Click event so that it resembles the following:

 ```vbnet
 Private Sub ShowDialog(ByVal sender As Object, ByVal e As RoutedEventArgs)
     Dim window = New C1Window()
     window.Content = New MyWindow()
     window.CenterOnScreen()
     Dim bgcol As New SolidColorBrush()
     bgcol.Color = Color.FromArgb(150, 255, 0, 0)
     window.ModalBackground = bgcol
     window.ShowModal()
 End Sub
 ```

 ```csharp
 void ShowDialog(object sender, RoutedEventArgs e)
 {
     var window = new C1Window();
     window.Content = new MyWindow();
     window.CenterOnScreen();
     SolidColorBrush bgcol = new SolidColorBrush();
     bgcol.Color = Color.FromArgb(150, 255, 0, 0);
     window.ModalBackground = bgcol;
     window.ShowModal();
 }
 ```

3. When you run your application now and click the **Open a modal window.** button, the background will be red:

 ![](https://cdn.mescius.io/document-site-files/images/7e9deccd-1f1c-4ec7-af90-b4332b45dead/images/windows/modalbackgroundproperty.png)

### Modeless Windows

A modeless dialog window enables users to interact with other windows while the dialog window is present. Use this type of dialog window when the requested information is not necessary to continue. Modeless dialog windows do not keep the input focus so you can work on two applications at once.

A modeless dialog window is commonly used in menus and help systems where the user can use the dialog window and the application window concurrently. For example, a toolbar is a modeless dialog window because it can be detached from the application and the user can select items in the toolbar to apply features to the detached or separated application.

You can show the **C1Window** control as a modeless dialog box using the [Show](/componentone/api/wpf/online-basiclibrary/dotnet-framework-api/C1.WPF.4.6.2/C1.WPF.C1Window.Show.html) method:

```vbnet
'The Show method is seen here in an If...Then...Else statement.
If showModal Then
        wnd.ShowModal()
    Else
        wnd.Show()
    End If
```

```csharp
//The Show method is seen here in an if...else statement.
if (showModal)
      wnd.ShowModal();
    else
      wnd.Show();
```