Adding Controls to a Form Using the Toolbox


The IDE offers some fantastic tools for building a graphical user interface (GUI) for your applications. Most GUIs consist of one or more forms (Windows) with various elements on the forms, such as text boxes and list boxes. The toolbox is used to place controls onto a form. Figure 2.7 shows the default toolbox you see when you first open or create a Visual C# project. These controls are discussed in detail in Hour 7, "Working with Traditional Controls," and Hour 8, "Using Advanced Controls."

Figure 2.7. The standard toolbox contains many useful controls you can use to build robust interfaces.


You can add a control to a form in one of four ways:

  • In the toolbox, click the tool representing the control that you want to place on a form, and then click and drag on the form where you want the control placed; you're essentially drawing the border of the control. The location at which you start dragging is used for one corner of the control, and the point at which you release the mouse button and stop dragging becomes the lower-right corner.

  • Double-click the desired control type in the toolbox. When you double-click a control in the toolbox, a new control of the selected type is placed in the upper-left corner of the form if the form is selected. If a control is selected when you do this, the new control will appear slightly to the right and down from the selected control. The control's height and width are set to the default height and width of the selected control type. If the control is a runtime only control, like the Open File Dialog control you used in Hour 1, it will appear below the form.

  • Drag a control from the toolbox and drop it on a form. If you hover over the form for a second, the toolbox disappears, and you can drop the control on the form anywhere you want.

  • Right-click an existing control and choose Copy, then right-click the form and choose Paste to create a duplicate of the control.

Did you Know?

If you prefer to draw controls on your forms by clicking and dragging, I strongly suggest that you dock the toolbox to the right or bottom edge of the design environment or float it. The toolbar tends to interfere with drawing controls when it's docked to the left edge because it covers part of the form.


The first item in each category in the toolbox, titled Pointer, isn't actually a control. When the pointer item is selected, the design environment is placed in a select mode rather than in a mode to create a new control. With the pointer item selected, you can click a control on the form to display all its properties in the Properties window.




Sams Teach Yourself Microsoft Visual C# 2005 in 24 Hours, Complete Starter Kit
Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
ISBN: 0672327406
EAN: 2147483647
Year: N/A
Pages: 248
Authors: James Foxall

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net