+-----------------------+ | Chapter 5 | | --------- | | Menus,SubProcedures & | | SubFunctions | +-----------------------+ ->Menus consist of a menu bar with menu names,each of which drops down to display a list of menu commands. ->Basically menus are used to activate the a procedure similiar to command buttons. ->Menus are the controls which has properties and events. ->Each menu is having a name property and click event. ->Each menu item has a Caption property (possibly with an embedded & character to create an access key) and a Name. Each item also exposes three Boolean properties, Enabled, Visible, and Checked, which you can set both at design time and at run time. Caption ------- It holds the words which one may want to appear on the screen( similiar to caption property of command button). For eg:File with a keyboard access key,use ampersand(&) in - Caption property .(&File). Name ---- It indicates the the name of menu control Naming Standards ---------------- The three character prefix for menu name is "mnu".Therefore the name for the File menu should be mnuFile. Submenus -------- ->When the command on the menu has another list of commands that pops up, the new list is called a submenu. ->A filled triangle to the right of the command indicates that a menu command has a submenu. Menu List Box ------------- It contains a list of menu items one may have created and shows their indentation levels. One can move the items displayed in menu list box towards left,right, top,bottom by clicking the respective arrow buttons. Seperator bars -------------- ->Basically used for gruping the commands according to their purpose. ->One can create a seperator bar in menu,which draws a bar across the entire menu. ->To define a seperator bar,type a single hyphen(-) for the caption and give it a name. Checked and Enabled ------------------- ->A menu command may contain a check mark beside it(checked),or it may be grayed(disabled). ->An enabled menu item appears in black text and is available for selection,whereas the grayed out or disabled items are not availabel. -> A checkmark placed next to a menu command usually indicates that the option is currently selected. +===================+ |Common Dialog Boxes| +===================+ ->Mainly used to predefined the standard dialog boxes for tasks such as specifying colors and fonts,printing, opening and saving. ->Its a custom control which allows us to use the dialog boxes that are provided as part of the windows environment. ->Place the control on the form. -> By default common dialog boxes are not displayed in toolbox. -> To add the control inside a toolbox,go to project menu and choose components & select Microsoft Common Dialog Control6.0 in the list.Place a checkmark next to control and the control will be added to toolbox. ->Naming convention-> "dlg" Using Common Dialog Control =========================== ->After placing a control on the form,one can display any of its dialog boxes at runtime. ->General Form: Object.ShowMethod ->This method can be one of the following: Dialog box Method ---------- ------ Open ShowOpen Save As ShowSave Color ShowColor Font ShowFont Print ShowPrint Eg: === Private Sub mnuEditColor_Click() 'Display the color Dialog box dlgCommon.ShowColor End Sub ------------------------------------------------------------------- Color Diallog box ================= ->When the user selects a color of his choice,the value of the color is stored in the Color Property. ->One can assign this property to another object such as a control or the form frmMain.BackColor=dlgCommon.Color ->Since VB executes the statements in sequence,one would first display the dialog box with ShowColor method and then use the color Property Private Sub mnuEditColor_Click() 'Display the color Dialog box dlgCommon.ShowColor 'Assign dialog box color to the form frmMain.BackColor=dlgCommon.Color End Sub ->By default,Color dialog Box takes black as color. ->One can initialize the box to show the form's currently selected color when it appears,one must set the controls Flags property to cdlCCRGBInit and set its Color Property before showing the dialog box. Private Sub mnuEditColor_Click() 'Display the color Dialog box With dlgCommon .Flags =cdlCCRGBInit 'Initialize the dialog Box .Color =frmMain.BackColor 'Set initial color .ShowColor End With 'Assign dialog box color to the form frmMain.BackColor=dlgCommon.Color 'Set color of form End Sub ------------------------------------------------------------------- Font Dialog Box =============== ->Again before using the ShowFont method,one must set the Flags property of the control. ->This allows the fonts to appear in ths list box. ->The value of the Flags property may be cdlCFScreenFonts,cdlCFPrinterFonts or cdlCFBoth. ->If one forget to set the flags,an error will appear at run time stating "There are no fonts installed" ->Group of properties for a Font object are given below: Font Object of Font Property of Other Controls CDC Values ============== ================ ======= Font.Bold FontBold True or False(Boolean) Font.Italic FontItalic True or False(Boolean) Font.Name FontName System dependent Font.Size FontSize Font dependent Font.StrikeThrough FontStrikeThru True or False(Boolean) Font.Underline FontUnderline True or False(Boolean) Private Sub mnuEditFont_Click() 'Display the font dialog box With dlgCommon .Flags = cldCFScreenFonts .ShowFont End With 'Assign dialog font to the label With lblEmployee.Font .Name =dlgCommon.FontName .Bold =dlgCommon.FontBold End With End Sub Setting Current values ---------------------- ->Before using CDB for coors and fonts,one must assign the existing values of the object properties that will be altered. ->This step will provide for the display of the current values in the dialog box. ->It also ensures that if the user selects the Cancel button,the property settings for the objects will remain unchanged. Private Sub mnuEditFont_Click() 'Display the font common dialog box and make chnges in label settings 'Assign current settings to dialog box With dlgCommon .FontName = lblEmployee.Font.Name .FontBold = lblEmployee.Font.Bold .FontItalic=lblEmployee.Font.Italic .FontSize = lblEmployee.Font.Size End With 'Set the method for Font dialog box With dlgCommon .Flags = cdlCFScreenFonts 'Specify screen Fonts .ShowFont End With 'Assign dialog box font to the label With lblEmployee.Font .Name = FontName .Bold = FontBold .Italic = FontItalic .Size = FontSize End With End Sub