7.3 Creating Modal Dialog Boxes

 <  Day Day Up  >  

You want to create a form and make it modal.


Technique

Add a new form to an existing Windows Forms project by selecting Project, Add Windows Form from the main menu. Because dialog boxes do not contain maximize and minimize buttons , change the MinimizeBox and MaximizeBox properties to False . To display the dialog box modally, create an instance of the Windows Form you created and call the ShowDialog method:

 
 private void Form1_Load(object sender, System.EventArgs e) {     this.Visible = true;     ModalForm newForm = new ModalForm();     newForm.ShowDialog( this ); } 

Comments

A modal dialog box displays information to a user requiring the user to close the dialog before proceeding. This box is helpful if you need to gather information from the user before your application proceeds or if you want to guarantee the user sees an informative message.

The technique shown earlier shows how to create a modal dialog box by changing the properties of a new form and displaying it with the ShowDialog method. One thing it doesn't explain is when the modal dialog appears. Of course, this factor depends on the requirement of your application. In most instances, the display depends on some event happening, likely fired as the result of user interaction. Chapter 5, "Delegates and Events," demonstrated how to create event handlers to handle events that are fired from an object. It comes as no surprise that Windows Forms use the same procedure to utilize event handling. However, because you are now able to use a visual editor, the process of creating event handlers is trivial. Recipe 7.5, "Handling Form Events," shows how to handle events in a Windows Form application.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net