Using Menu Bar Common Dialog Boxes Slide 1
Using Menu Bar & Common Dialog Boxes Slide 1
Setting Up the Main Items First open the form on which you want the menu located v Then start the Menu Editor in any of three ways: v – click the Menu Editor button on the toolbar; – choose Tools, Menu Editor; – or press Ctrl+E. The Menu Editor then appears, as: Slide 2
Menu Controls v Each line of text (menu item) in a menu is a Menu control with the following properties: – Caption: The caption is the actual text that is displayed in the menu item. – Name: This property is used to identify the menu item in code. – Index: If this menu item is part of control array, – Shortcut: With this property, you can define shortcut key combinations that allow your users to select a menu item with one keystroke, – Checked: If this property is True, a check mark appears to the left of the menu item’s caption to indicate, – Enabled: This property can be set to False if its associated action isn’t appropriate at a particular time. – Visible. This property determines whether the menu item can be seen. Slide 3
Multiple-Level Menus in Windows-based applications contain multiple levels of commands. v Top-level menu items are the ones that are visible in the program’s menu bar. v Clicking a toplevel menu item opens that item’s submenu. v You can then insert separator bars to group the related functions. v Slide 4
Writing Code for the Menu Items A menu item handles only one event: the Click event. v This event is triggered when a user clicks the menu item, or when the user selects the item and presses Enter. v To add code to a menu item’s Click event procedure, first select the menu item on the form by clicking the item, then write the event procedure. v Slide 5
Other Properties v The Visible and Enabled Properties: – – v mnu. File. Save. Enabled = True mnu. File. Send. To. Enabled = True mnu. File. Print. Enabled = True mnu. Edit. Visible = True The Checked Property – mnu. Options. Text. Checked = True – mnu. Options. Text. Checked = Not mnu. Options. Text. Checked Slide 6
Common. Dialog Control v Using a single Common. Dialog control, you have access to the following standard Windows dialog boxes: – Open. Lets the user select the name and location of a file to open. – Save As. Lets the user specify a filename and location in which to save information. – Font. Lets the user choose a base font and set any font attributes that are desired. – Color. Lets the user choose from a standard color or create a custom color for use in the program. – Print. Lets the user select a printer and set some of the printer parameters. – Help. Takes the user into the Windows Help system. Slide 7
Common. Dialog Control To access the Common. Dialog control, you might first have to add it to your project (and to the Toolbox) by selecting it from the Components dialog box. v You can access this dialog box by choosing Project, Components. From there, select Microsoft Common Dialog Control 6. 0 in the Controls list and click OK. v Slide 8
The File Dialog Boxes File dialog box can be used in either of two modes: Open and Save As. v Opening Files: v – cdl. Test. Show. Open – Msgbox “You Selected “ & cdl. Test. File. Name & “ to be opened. ” v Saving Files: – cdl. Test. Show. Save – Msgbox “You Selected “ & cdl. Test. File. Name & “ to be saved. ” v Specifying File Types with the Filter Property: – cld. Test. Filter = “Word Documents (*. doc)|*. doc” – cdl. Test. Filter = “Text Files (*. txt)|*. txt|All Files (*. *)|*. *” – cdl. Test. Show. Open Slide 9
The Font Dialog Box v Flags property If you do not set a value for the Flags property, you get an error message stating that no fonts are installed. v Example: v – – – cdl. Test. Flags = cdl. CFBoth + cdl. CFEffects cdl. Test. Show. Font lbl. Test. Font. Name = cdl. Test. Font. Name lbl. Test. Font. Size = cdl. Test. Font. Size lbl. Test. Font. Bold = cdl. Test. Font. Bold Slide 10
The Font Dialog Box v Setting a text box font – Set txt. Address. Font = txt. Name. Font Slide 11
The Color Dialog Box v You set the Flags property to the constant cdl. CCRGBInit and then invoke the control’s Show. Color method. – cdl. Test. Flags = cdl. CCRGBInit – cdl. Test. Show. Color – Form 1. Back. Color = cdl. Test. Color Slide 12
- Slides: 12