This documentation is archived and is not being maintained.

Displaying Dialog Boxes for Windows Forms

Visual Studio .NET 2003

You display a dialog box in the same way you display any other form in an application. The startup form loads automatically when the application is run. To make a second form or dialog box appear in the application, write code to load and display it. Similarly, to make the form or dialog box disappear, write code to unload or hide it.

To display a dialog box

  1. Navigate to the event handler with which you want to open the dialog box. This can happen when a menu command is selected, when a button is clicked, or when any other event occurs.
  2. In the event handler, add code to open the dialog box. In this example, a button-click event is used to show the dialog box:
    ' Visual Basic
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim dlg1 as new Form()
    End Sub
    // C#
    private void button1_Click(object sender, System.EventArgs e) 
       Form dlg1 = new Form();
    // C++
      System::Void button1_Click(System::Object *  sender,
        System::EventArgs *  e)
        Form *dlg1 = new Form();

    For more information on the ways to show forms and dialog boxes, see Displaying Modal and Modeless Windows Forms.

See Also

Dialog Boxes in Windows Forms | Creating Dialog Boxes | Creating Windows Forms