8.3. Adding and Positioning Controls

You can add two types of controls to your Windows Forms: graphical components that actually reside on the form itself, and components that do not have a specific visual interface displaying on the form.

You add graphical controls to your form in one of two ways. The first is to locate the control you want to add in the Toolbox and double-click its entry. Visual Studio 2008 will place it in a default location on the form — the first control will be placed against the top and left borders of the form, with subsequent controls tiled down and to the right.

The second method is to click the entry on the list and drag it onto the form. As you drag over available space on the form, the mouse cursor will change to show you where the control will be positioned. This enables you to directly position the control where you want it, rather than first add it to the form and then move it to the desired location. Either way, once the control is on the form, you can move it as many times as you like, so it doesn't really matter how you get the control onto the form's design surface.

There is actually one other method to add controls to a form — copy and paste a control or set of controls from another form. If you paste multiple controls at once, the relative positioning and layout of the controls to each other will be preserved. Any property settings will also be preserved, although the control names may be changed.

When you design your form layouts in SnapLines ...

Get Professional Visual Studio® 2008 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.