Download Delphi User's Guide
Transcript
Figure 12.8 Line after rubber banding You’ve come a long way with your line drawing, and as you’ll see shortly, it will all pay off when you want to draw different shapes, such as rectangles and ellipses. Before you can draw those shapes, however, you need to add a way for the user to choose which shape to draw. In the next section, you’ll define a tool bar that provides those choices, then see how to respond to the tool bar’s controls. Adding a tool bar to a form A tool bar is a panel, usually across the top of a form, below the menu bar, that holds a number of controls, especially buttons. Tool bars provide an easy, visible way to present options to users of your applications, and Delphi makes it easy to add tool bars to your forms. ■ To add a tool bar to a form, 1 Add a Panel component to the form. 2 Set the panel’s Align property to alTop. When aligned to the top of the form, the panel maintains its height, but matches its width to the full width of the form’s client area, even if the window changes size. 3 Add speed buttons or other controls to the bar. You can add as many tool bars to a form as you want. If you have multiple panels aligned to the top of the form, they “stack” vertically in the order added. ➤ Add a tool bar to the graphics-example form and delete its caption. In the next section, you’ll add buttons to the tool bar. Later in this example, you’ll add more tool bars to the form, and see how to show and hide them at run time. Adding speed buttons to a tool bar Delphi provides buttons, called speed buttons, specially designed to work on tool bars. A speed button usually has no caption, only a small graphic called a glyph, which represents the button’s function. Chapter 12, Graphics example 331