1 / 12

Using Menu Bar & Common Dialog Boxes

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.

fayemoore
Télécharger la présentation

Using Menu Bar & Common Dialog Boxes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Menu Bar&Common Dialog Boxes

  2. 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:

  3. 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.

  4. 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.

  5. 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.

  6. 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

  7. 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.

  8. 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.

  9. 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

  10. 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

  11. The Font Dialog Box • Setting a text box font • Set txtAddress.Font = txtName.Font

  12. 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

More Related