ADDING CONTROLS

The WPF Designer allows you to add controls to a form in several ways that are similar to those provided by the Windows Forms Designer. If you are familiar with that topic you might want to skip this section.

First, if you double-click a control on the Toolbox, Visual Studio places an instance of the control on the window in a default location and at a default size. You can then use the mouse to move and resize the control.

CONTAINER CONFUSION
When you use this method, the new control is placed inside the currently selected container on the window. If the currently selected control is a StackPanel, the new control is placed inside the StackPanel. If the currently selected control is a TextBox that is inside a Grid, the new control is placed inside the Grid.

Second, if you click a control in the Toolbox, the mouse cursor changes to a crosshair while the mouse is over the window. If you click the window, Visual Studio adds a control at that location with a default size. Instead of just clicking, you can click and drag to specify the new control’s location and size.

If you hold down the Ctrl key when you select a tool from the Toolbox, that tool remains selected even after you create a control on the window so you can add another instance of the control. For example, suppose you need to create a series of TextBoxes to hold a user’s name, street, city, state, and ZIP code. Hold the Ctrl key and click the TextBox tool in the Toolbox. Then you can quickly click ...

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.