Form Styles


Chapter 2: Forms introduced the important dialog-related properties: ControlBox, FormBorderStyle, HelpButton, MaximizeBox, MinimizeBox, ShowIcon, and ShowInTaskbar. By default, a new form shows the control box, is sizable, doesn't show the help button, can be minimized and maximized, and is shown in the shell's task bar. For a main window, these are fine settings, and they yield a form that looks like the one in Figure 3.1.

Figure 3.1. Typical Main Window Form Settings


A typical modal dialog, on the other hand, is more likely to hide both the minimize and the maximize boxes, show the help button, hide the icon, and not show up in the task bar (the parent is already there), as shown in Figure 3.2.

Figure 3.2. Typical Sizable Modal Form Settings


Interestingly, even though SizeGripStyle is set to its default of Auto, the size grip is automatically shown for modal forms (Figure 3.2), but it is not shown for main windows (Figure 3.1). Also, while the ControlBox property remains true when the border style is changed to FixedDialog, the icon is not shown when ShowIcon is set to true, as you can see in Figure 3.3.

Figure 3.3. Typical Fixed Modal Form Settings


Clearly, Windows Forms has its own ideas about what to show along the edge of your form, sometimes disregarding your preferences. Except for FormBorderStyle, typical modeless form settings are just like the sizable modal form settings (from Figure 3.2) except that calling Show instead of ShowDialog causes the size grip to go away.

These examples should serve most of your needs, although it's possible to vary form properties to get a few more variations. For example, you can use the border styles FixedToolWindow and SizableToolWindow to show the caption in miniature (handy for floating tool strip or tool box windows).

Deciding on Modal Versus Modeless at Run-Time

If you'd like your form to change its settings based on whether it's being shown modally, check its Modal property:

void ModalOrModelessDialog_Load(object sender, EventArgs e) {   if( this.Modal ) {     // Show as a fixed-sized modal dialog     this.FormBorderStyle = FormBorderStyle.FixedDialog;   }   else {     // Show as a sizable modeless dialog     this.FormBorderStyle = FormBorderStyle.Sizable;   } }


Depending on whether the form is shown using ShowDialog or Show, the Modal property is true or false, respectively. However, because the way a form is shown isn't known until after it has been created, you can't use the Modal property when it is inspected from a form's constructor, because it is always false at that time. However, you can use the Modal property value during and after the Load event.




Windows Forms 2.0 Programming
Windows Forms 2.0 Programming (Microsoft .NET Development Series)
ISBN: 0321267966
EAN: 2147483647
Year: 2006
Pages: 216

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