• Aucun résultat trouvé

Creating and Saving Menu Templates

Dans le document Teach Yourself Borland Delphi 4 in 21 Days (Page 189-192)

Delphi provides you with several menu templates that you can insert into your main menus and pop-ups. You can also create and save your own templates for future use in your programs. First, start the Menu Designer and create the menu.

NOTE: When creating menus to use as templates, you first must have a main menu or a pop-up menu on a form in order to start the Menu Designer. You can use a temporary, blank form if you want. Start with a blank form, place a MainMenu component on it, and double-click the menu component's icon to start the Menu Designer.

After you are done creating menu templates, discard the blank form without saving.

When you have created the menu, choose Save As Template from the Menu Designer's context menu. The Save Template dialog box is displayed. Give the menu a meaningful name and click the OK button, and the menu is saved as a template. To insert the menu, choose Insert From Template from the Menu Designer's context menu just as you did earlier. Any menus you have created will show up along with Delphi's prebuilt templates.

To remove a template that you previously added, choose Delete Templates from the Menu Designer's context menu. The Delete Templates dialog box is displayed, and you can choose the templates you want to delete. When you click the OK button, the selected menu templates will be deleted. Press Cancel to close the dialog box without deleting any templates.

Summary

Congratulations! You have just covered the bulk of the Delphi visual programming features. I hope it was enjoyable as well as educational. The Form Designer is a powerful tool that enables you to do as much programming as possible in a visual manner.

If you haven't had to create windows and dialogs using traditional Windows programming tools, you might not fully appreciate that advantage. Trust me, it's significant. The Menu Designer is also a powerful tool, particularly because of the capability to import menus, which makes menu creation easy and actually fun with Delphi. The Menu Designer also makes updating existing menus a snap.

Workshop

The Workshop contains quiz questions to help you solidify your understanding of the material covered and exercises to provide you with experience in using what you have learned. You can find the answers to the quiz questions in Appendix A, "Answers to the Quiz Questions."

Q&A

Q I'm using the Alignment palette a lot, and every time I switch from the Code Editor back to the Form Designer, the Alignment palette gets lost somewhere. Is there anything I can do about that?

A Locate the Alignment palette (it's there somewhere!) and click your secondary mouse button to bring up the Alignment palette's context menu. Choose the Stay on Top item from the context menu. Now the Alignment palette will always be on top where you can find it.

Q I am trying to select a group of components on a panel by dragging the selection rectangle around them, but I keep moving the panel. What's wrong?

A You need to hold down the Ctrl key while dragging when you are selecting components contained on a panel.

Q I've moved my components around my form several times and now the tab order is erratic. What can I do to fix that?

A Choose Tab Order from the Form Designer's context menu. Arrange the tab order the way you want it. When you click OK, the new tab order will be implemented.

Q The menu templates provided are nice, but they have so much stuff on them that I don't need. What can I do about that?

A You can do two things. First, you can import a menu and then simply delete the items you don't want. Using the click, Shift+click method you can get rid of unwanted menu items in just a few seconds. Deleting items from a menu inserted from a template has no adverse effects. The second thing you can do is to follow the click, Shift+click method and then, when you have the menu just the way you want it, you can save it as a new template. That way you can keep the original Delphi-supplied template and have your customized template as well.

Q Can I save my own menus as templates?

A Yes. First create the menu and then choose Save As Template from the Menu Designer context menu. Give the template a name, click OK, and the template is saved. Now all you have to do to reuse the menu later is insert the menu using the Insert From Template feature.

Quiz

1. When do you use Ctrl+drag in selecting components?

2. What significance does the first component selected have when aligning a group of components?

3. What is the quickest method to select a group of components?

4. How can you make a group of components all have the width of the group's widest component?

5. What happens when you double-click a component on a form?

6. What does the Align property's alClient option do?

7. What does the ellipsis following a menu item mean?

8. What two ways can you move a menu item?

9. How do you add menu accelerators to menu items?

10. How do you initially disable a menu item?

Exercises

1. Place five edit components on a form and arrange them so that they are stacked vertically with their left edges aligned.

2. Turn the Snap to Grid option off (choose Tools | Environment Options from the main menu). Place five controls of your choice on a form and align their right edges.

3. Place a ListBox component on a blank form and modify it so that it always occupies the form's entire client area.

4. Add an About box to the ScratchPad program. Use the Alignment palette to quickly align the text labels.

5. Add an Undo item and a menu separator to the context menu for the ScratchPad program.

6. Start a new application. Place six edit components on a form in random fashion. Now arrange the tab order so that tabbing proceeds from top to bottom. Run the program to test the tabbing order.

7. Add the Ctrl+S keyboard shortcut to the File | Save menu item in the ScratchPad program.

8. Open the Picture Viewer project you created on Day 4. Remove all unused menu items.

© Copyright, Macmillan Computer Publishing. All rights reserved.

Teach Yourself Borland Delphi 4 in 21

Dans le document Teach Yourself Borland Delphi 4 in 21 Days (Page 189-192)