VB.NET Developer's Guide

Adding Controls to Forms

Most forms contain controls that display information to the user or collect information from the user. These controls are most often added to the form at design time. You can add a control to a form at design time in several ways:

  1. From the View menu, select Toolbox.
  2. On the Toolbox window, select the Win Forms tab.
  3. Double-click the appropriate control.

Or:

  1. Click the appropriate control.
  2. On the form, click or drag the mouse.

You can arrange controls on forms in many ways. You can anchor, dock, layer, and position controls on forms. In the following sections, we discuss these different ways to arrange controls on forms.

Anchoring Controls on Forms

The controls on a resizable form should resize and reposition properly when the user resizes the form. In previous versions of Visual Basic, this required extensive coding or a custom component to carry out control resizing and repositioning. In Visual Basic .NET, you can use the Anchor property of Windows Forms controls. The Anchor property determines to which edges of the container a control is bound. When a control is anchored to an edge, the distance between the control s closest edge and the specified edge will remain constant. Say for example that you have a combo box that is anchored to the top, left, and right edges of a form (see Figure 7.2).


Figure 7.2: A Combo Box Anchored to the Top, Left, and Right Edges of a...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Computer Mice and Pointing Devices
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.