Description.

Forms / Dialogs are a fundamental part of most applications. Here we will
show how to build, display and interact with a dialog. It will be built using
both Modal and Modeless types. This is a very simple task so don't get lost in
the details.

Create a simple dialog.

The following steps will create a Form (Dialog) in your current project. The
dialog will have an OK button and a edit box.

Using Visual Studio.NET open the the project you want to add the Dialog
to.

From the Project menu select Add Windows Form...

In Categories select Local Project Items (default).

In the Name field type the name of the class to call the form.
include a .cs extension. It is nice to prefix the name with Frm ie
FrmOpenFile. If you have trouble thinking of names look into using Hungarian
notation.

In Templates select Windows Form.

Select OK. The Form will appear.

From the View menu select Toolbox.

Drag a Text box onto the new form.

Right click on the text box and select properties.

Change (Name) to m_tbAddress.

Change Modifiers to Public.

From the Toolbox drag a Button onto the form.

Right click on the button and select properties.

Change Text to "OK".

Change DialogResult to OK.

Displaying a Modal Dialog box.

A Modal dialog takes control of the applications user interface requiring the
dialog to be dealt with and closed before other views of the application are able
to receive input from the user. For example the File Open dialog prohibits the
user doing anything with that application until the dialog is cancelled or a file
is selected for opening.

The following creates the dialog box, but does not display it. The m_tbAddress
property is set. This will pre-fill the data. ShowDialog displays
the dialog and waits for the dialog to close before continuing. If the return
code from the Show is OK the data is read back from the dialog and displayed.

Displaying a Modeless Dialog box (Popup).

A Modeless dialog allows both the owner and sub windows to receive user input.
The owner window can be forced to always appear beneath the Modeless window by
calling AddOwnedForm. However, if this is not called the modeless window can appear in front of behind the owner window depending on who has
focus. An example of a owned modeless dialog would be a tool bar when it is not
docked.

The modeless window is slightly more difficult to process because it must
notify the parent when it has been destroyed. If you fail to do this you should
check if the form is Visible or Disposed before doing
any thing with it.

The following code creates a modeless dialog that is toggled into existence. When first called it is created. The next time it is called it is
destroyed.

To get the modeless to disappear when the OK button is pressed we need to add
the following code to the form code. Open the form in design mode and double
click on the OK button. This will take you to the code view. Insert Dispose()
as shown. Note: I have named the button "m_btnOK" in place of the default "button1"

Usually we would also add some code to inform the owner that we are done with
the form. Remember, always take the time to name your variables intuitively. A
few extra characters here and there can make the difference between happiness
and a bawled head 3 months later when you return to add a feature.

I have two modless windows that a messagbox opens on top of them. The modal message box does not dispose of them. Checking the dispose of property in the debugger the dispose of property is false. I don`t understand why they disapper. Any insight into this problem?