364 Part III Designing the User Interface
Notice that you can’t resize the second form because FormBorderStyle was set to
FixedDialog.
- Close the second form, and then close the first form.
Your program stops running, and the IDE returns.
- Click the Save All button, and then specify the C:\Vb10sbs\Chap14 folder as the location.
Minimizing, Maximizing, and Restoring Windows
In addition to establishing the size and location of a Visual Basic form, you can minimize
a form to the Windows taskbar, maximize a form so that it takes up the entire screen, or
restore a form to its normal shape. These settings can be changed at design time or at run
time based on current program conditions.
To allow a form to be both minimized and maximized, you must first verify that the form’s
minimize and maximize boxes are available. Using the Properties window or program code,
you specify the following settings:
form2.MaximizeBox = True
form2.MinimizeBox = True
Then, in program code or by using the Properties window, you set the WindowState
property for the form to Minimized, Maximized, or Normal. (In code, you need to add the
FormWindowState constant, as shown below .) For example, the following program statement
minimizes form2 to the Windows taskbar:
form2.WindowState = FormWindowState.Minimized
If you want to control the maximum or minimum size of a form, set the MaximumSize
or MinimumSize properties at design time by using the Properties window. To set the
MaximumSize or MinimumSize in code, you’ll need to use a Size structure (which is similar
to the Rectangle structure used in the previous exercise), as shown here:
Dim FormSize As New Size(400, 300)
form2.MaximumSize = FormSize
Adding Controls to a Form at Run Time
Throughout this book, you’ve added objects to forms by using the Toolbox and the Designer.
However, as the previous exercise demonstrated, you can also create Visual Basic objects
on forms at run time, either to save development time (if you’re copying routines you have
used before) or to respond to a current need in the program. For example, you might want
to generate a simple dialog box containing objects that process input only under certain
conditions.