Styles


>Chapter 2 : Forms introduces the important dialog- related properties: ControlBox, FormBorderStyle, HelpButton, MaximizeBox, MinimizeBox, 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 taskbar. For a main window, these are fine settings and will yield a form that looks like the one in Figure 3.1.

Figure 3.1. Typical Main Window Form Settings

A typical modal form, on the other hand, is more likely to hide the minimize and maximize boxes, to show the help button, and to choose not to show up in the taskbar (the parent will already be there), as shown in Figure 3.2.

Figure 3.2. Typical Modal Form Settings

You may find it interesting that even though the SizeGripStyle hasn't changed from its default of Auto between the main window and the modal form examples, by default the size grip is shown only when the form is shown modally. Similarly, although the ControlBox property remains true when the border style is changed to FixedDialog, the control box will not be shown, as you can see in Figure 3.3. Clearly, WinForms has its own ideas about what to show along the edge of your form, sometimes disregarding your preferences.

Figure 3.3. Typical Modal Form Settings

Typical modeless form settings are just like the sizable modal form settings (shown in 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 certainly 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 toolbar or toolbox windows ).

Setting Modal Versus Modeless Behavior Dynamically

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

 
 Sub LoanApplicationDialog_Load(sender As Object, e As EventArgs) _       Handles MyBase.Load  If Me.Modal Then  ' Show as a fixed-sized modal dialog       Me.FormBorderStyle = FormBorderStyle.FixedDialog  Else  ' Show as a sizable modeless dialog       Me.FormBorderStyle = FormBorderStyle.Sizable  End If  End Sub 

Depending on whether the form was shown using ShowDialog or Show, the Modal property will be true or false, respectively. However, because the way a form is shown isn't known until after it's been created, the Modal property isn't accurate in the constructor and will always be false at that time. You will be able to get the form's actual Modal property value only in the Load event or later.



Windows Forms Programming in Visual Basic .NET
Windows Forms Programming in Visual Basic .NET
ISBN: 0321125193
EAN: 2147483647
Year: 2003
Pages: 139

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