Regardless of how long you have been using C++Builder there are no doubt features of the IDE that you have overlooked. This article will explain some lesser-known features of the IDE Form Designer.
As you develop an application, you often need to select the form you are currently working on in order to change a property value or to generate an event handler. In some cases selecting the main form is as simple as clicking on the form. In many cases, though, the form may be completely obscured by the components that it contains.
One way to select a form that is covered with components is to use the Object Selector combo box at the top of the Object Inspector. This works, but it can be difficult to find the form class in the list of components, particularly if the form contains a large number of components.
Fortunately, the Form Designer offers a shortcut to selecting a form. Let’s say, for example, that you have a Memo component aligned to the client area of the form. To select the form, simply click on the Memo and hit the Esc key on the keyboard. When you hit the Esc key, the Form Designer will select the form.
What actually happens is that the Form Designer changes the selection to the parent of the component that was originally selected. If you have a component on a panel, for example, you can click on the component and then hit Esc to select the panel. If the panel itself is located directly on the form, hitting Esc again will select the form.
Panels are often used as containers for other components. You may want to select a number of components on the panel in order to move them, or to change the value of a common property. You can, of course, simply use Shift-click to select the components. If you try to select components by dragging with the mouse, though, you will end up moving the panel. To select components on the panel by dragging, hold down the Ctrl key while dragging. Now you can drag to select components on the panel without moving the panel itself. This works for any component that acts as a container for other components (GroupBox, ScrollBox, ControlBar, and so on).
Once you have placed a component on a form, you often need to move it slightly. You can move a component one pixel at a time by holding down the Ctrl key and pressing any of the arrow keys. Holding down both the Shift and the Ctrl keys will move the component to the next grid point when an arrow key is pressed.
To size a component one pixel at a time, hold down the Shift key and press any of the arrow keys. Note that the width of the component changes when you press either the right or left arrow keys, and that the height of the component changes when you press the up or down arrow keys.
When you select multiple components, the Object Inspector will display only those properties that the selected components have in common. Let’s say, for example, that you have several Edit components on a form and that you want to make them all the same width. Just select all of the components and then change the Width property in the Object Inspector. The width of all selected components will change to reflect the new value. This is a convenient way of clearing the text from several Edit components at one time.
Often you need to make sure a group of components are aligned to one another in a specific way. For example, you may want an Edit component and its associated Label centered on one another. First select the Edit component, hold down the Shift key, and then select the Label component. Next, right-click on one of the selected components and choose Align from the context menu. The Alignment dialog comes up, allowing you to align the components in several ways. In this case you would select the Centers radio button in the Vertical radio group. When you click OK, the Edit component and Label will be centered on one another vertically.
There is one aspect of using the Align dialog that I should point out, and that is the concept of the anchor component. The first component of a group you select will act as the anchor component. That is, the anchor component will stay where it is, and all other components will move according to the alignment options you selected.
Finally, remember that the Alignment Palette does essentially the same thing as the Alignment dialog does. To use the Alignment Palette, choose View | Alignment Palette from the C++Builder main menu.
For some of you, this article may appear to be ridiculously introductory. However, I would be willing to bet that most of you have learned something about the Form Designer that you did not previously know. The RAD aspect of C++Builder is impressive, and this is particularly true once you learn how to use the IDE to its fullest extent.