130 likes | 158 Views
Using Menu Bar & Common Dialog Boxes. Setting Up the Main Items. First open the form on which you want the menu located Then start the Menu Editor in any of three ways: click the Menu Editor button on the toolbar; choose Tools, Menu Editor; or press Ctrl+E.
E N D
Setting Up the Main Items • First open the form on which you want the menu located • Then start the Menu Editor in any of three ways: • click the Menu Editor button on the toolbar; • choose Tools, Menu Editor; • or press Ctrl+E. The Menu Editor then appears, as:
Menu Controls • 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 ofcontrol array, • Shortcut: With this property, you can define shortcut key combinations that allow yourusers 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.
Multiple-Level Menus • Menus in Windows-based applications contain multiple levels of commands. • Top-level menu items are the ones that are visible in the program’s menu bar. • Clicking a toplevel menu item opens that item’s submenu. • You can then insert separator bars to group the related functions.
Writing Code for the Menu Items • A menu item handles only one event: the Click event. • This event is triggered when a user clicks the menu item, or when the user selects the item and presses Enter. • 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.
Other Properties • The Visible and Enabled Properties: • mnuFileSave.Enabled = True • mnuFileSendTo.Enabled = True • mnuFilePrint.Enabled = True • mnuEdit.Visible = True • The Checked Property • mnuOptionsText.Checked = True • mnuOptionsText.Checked = Not mnuOptionsText.Checked
CommonDialog Control • Using a single CommonDialog 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.
CommonDialog Control • To access the CommonDialog control, you might first have to add it to your project (and to the Toolbox) by selecting it from the Components dialog box. • 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.
The File Dialog Boxes • File dialog box can be used in either of two modes: Open and Save As. • Opening Files: • cdlTest.ShowOpen • Msgbox “You Selected “ & cdlTest.FileName & “ to be opened.” • Saving Files: • cdlTest.ShowSave • Msgbox “You Selected “ & cdlTest.FileName & “ to be saved.” • Specifying File Types with the Filter Property: • cldTest.Filter = “Word Documents (*.doc)|*.doc” • cdlTest.Filter = “Text Files (*.txt)|*.txt|All Files (*.*)|*.*” • cdlTest.ShowOpen
The Font Dialog Box • Flags property • If you do not set a value for the Flags property, you get an error message stating that no fonts are installed. • Example: • cdlTest.Flags = cdlCFBoth + cdlCFEffects • cdlTest.ShowFont • lblTest.Font.Name = cdlTest.FontName • lblTest.Font.Size = cdlTest.FontSize • lblTest.Font.Bold = cdlTest.FontBold
The Font Dialog Box • Setting a text box font • Set txtAddress.Font = txtName.Font
The Color Dialog Box • You set the Flags property to the constant cdlCCRGBInit and then invoke the control’s ShowColor method. • cdlTest.Flags = cdlCCRGBInit • cdlTest.ShowColor • Form1.BackColor = cdlTest.Color