Adding Controls to a Form

   Tasks

Most forms are designed by adding controls to the surface of the form to define a user interface. A control is a graphical component on a form that is used to display information or accept user input. Controls can also be hidden components that provide functionality in an application.

When adding graphical controls to a form, it is important to pick the right control. For example, you can use a ListView control instead of a ListBox control to display more information when selecting from a list of options. When deciding which control to use, determine how much information the user needs to see or provide, and select a control that provides the logical way to display or retrieve the data.

To add a control to a form

Resizing a Control

After you add a control to your form, you can resize it so that it appears appropriately in the user interface.

Note   Some controls, such as the ComboBox control, have absolute sizing and will not resize beyond a size specified by the control. Typically, absolute sizing applies to either the height or width of a control.

To resize a control

As you add controls to a form, you may find it easier to add a control and specify its size at the same time. You can do this by drawing the control onto the form instead of double-clicking or dragging the control onto the form.

To draw a control onto a form

  1. In the Toolbox, click the control you want to add to your form.

  2. On the form, click the area of the form where you want the control's upper-left corner to be located.

  3. While holding down the left mouse button, drag to the location on the form where you want the lower-right corner of the control to be located.

  4. Release the mouse button.

    The control is added to the form with the specified location and size.

Adding Controls to a Container

Some controls are known as containers and are used to store other controls. Container controls are similar to forms in many ways. For example, controls that are added to a container control are moved when the container control is moved.

To add a control to a container

Copying Controls

While designing a form, you can copy a control or a group of controls that you have added and set the appearance for onto a different form or another location on your current form.

To copy controls from one form to another

  1. In the Forms Designer, open the form that you want to copy a control or group of controls from.

  2. Select the controls that you want to copy.

    You can select multiple controls by holding down the CTRL key while selecting the controls.

  3. On the Edit menu, click Copy.

  4. In the Forms Designer, open the form that you want to paste the controls onto.

  5. On the Edit menu, click Paste to paste the controls onto the form.

    The controls appear in the upper-left corner of the form. You can then reposition them if necessary.