Database Reference
In-Depth Information
The second parameter you are provided with is Caption , which is the title of the dialog. We hard-
coded this as “Welcome,” and then we chose our button set through MessageBoxButtons.OKCancel . The
final argument we passed is MessageBoxIcon and used an information type icon.
Note MessageBox.Show() is very powerful and handy function; you may want to play a little more with various
choices that IntelliSense shows for the MessageBoxButtons and MessageBoxIcon type arguments.
Setting Dock and Anchor Properties
Prior to Visual Studio 2005, resizing Windows forms would require you to reposition and/or resize
controls on those forms. For instance, if you had some controls on the left side of a form and you tried to
resize the form by stretching it toward the right side or bringing it back toward the left, the controls
wouldn't readjust themselves according to the width of the resized form. Developers were bound to
write code to shift controls accordingly to account for the user resizing the form. This technique was very
code heavy and not so easy to implement.
With Visual Studio 2005 and onwards came two new properties, Anchor and Dock, which are easy to
set at design time. The same Dock and Anchor properties are available with Visual Studio 2012, and they
solve the problem with the behavior of controls that users face while resizing forms.
Dock Property
The Dock property allows you to attach a control to one of the edges of its parent. The term parent
applies to Windows forms, because Windows forms contain the controls that you drag and drop on
them. By default, the Dock property of any control is set to None.
For example, a control docked to the top edge of a form will always be connected to the top edge of
the form, and it will automatically resize in the left and right directions when its parent is resized.
The Dock property for a control can be set by using the provided graphical interface in the
Properties window, as shown in Figure 9-11.
Figure 9-11. Setting the Dock property
 
Search WWH ::




Custom Search