1 / 10

Adding Common Dialog Control

Adding Common Dialog Control. Not on standard Toolbox To add this custom control, select Components from Project menu. Common Dialog Control. Custom control that allows VB program to use dialog boxes provided with Windows Color File Font Print Hungarian notation: dlgNameOfControl

elysia
Télécharger la présentation

Adding Common Dialog Control

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. Adding Common Dialog Control • Not on standard Toolbox • To add this custom control, select Components from Project menu

  2. Common Dialog Control • Custom control that allows VB program to use dialog boxes provided with Windows Color File Font Print • Hungarian notation: dlgNameOfControl • Size of dialog box is controlled by Windows and cannot be changed by program • Only one control is needed to access all standard dialog boxes by the form

  3. Control Color: Common Dialog • Place common dialog control on form (it remains invisible during execution) • To allow the user to control the color aspect of one or more objects, write an event procedure (e.g., mnuEditColor_Click) with the following logic 1) Assign defaults to dialog box: dlgName.Flags = cdlCCRGBInit ‘ initialize dialog box dlgName.Color = frmName.BackColor ‘ assign backcolor on form 2) Display the desired standard dialog box to user: Call dlgName.ShowColor 3) Apply information from dialog box selected by user to program: frmName.BackColor = dlgName.Color lblNumber.ForeColor = dlgName.Color

  4. Control Font: Common Dialog • Place common dialog control on form (it remains invisible during execution) • To allow the user to control the font aspect of one or more objects, write an event procedure (e.g., mnuEditFont_Click) with the following logic 1) Assign defaults to dialog box: dlgName.FontBold = lblNumber.Font.Bold dlgName.Flags = cdlCFScreenFonts ‘ install fonts to show in list box ‘ see below to include color, strikethru & underline on font dialog dlgName.Flags = cdlCFEffects Or cdlCFScreenFonts 2) Display the desired standard dialog box to user: Call dlgName.ShowFont 3) Apply information from dialog box as selected by user to program: lblNumber.Font.Name = dlgName.FontName lblNumber.Font.Bold = dlgName.FontBold lblNumber.Font.Italic = dlgName.FontItalic lblNumber.ForeColor = dlgName.Color

  5. Control File Access: Common Dialog • Place common dialog control on form (it remains invisible during execution) • Example: mnuOpenPicture_Click lets user pick image 1) Optional: adjust window parameters to better inform user: dlgCommon.Flags = cdlOFNFileMustExist ' file must exist flag dlgCommon.DefaultExt = ".gif" ' default extension .gif dlgCommon.Filter = ”Picture (*.gif)| *.gif" ' filter show these files ' customize the title bar of the dialog box dlgCommon.DialogTitle = "OPEN--Please select picture file” 2) Display the desired standard dialog box to user: Call dlgName.ShowOpen 3) To use information from dialog box selected by user: imgFlag.Picture = LoadPicture(dlgName.FileName)

  6. Updated Colorful Hello World

  7. Updated Colorful Hello World • Allowing the user to change background colors ' Purpose: The Color Palette appears with the current options shown as ' defaults. Any changes made by the user appear on the form. Private Sub mnuEditChangeBackColor_Click() dlgCommon.Flags = cdlCCRGBInit ' initialize dialog box dlgCommon.Color = frmMain.BackColor ' assign backcolor on form Call dlgCommon.ShowColor frmMain.BackColor = dlgCommon.Color fraLanguage.BackColor = dlgCommon.Color optEnglish.BackColor = dlgCommon.Color optSpanish.BackColor = dlgCommon.Color optHindi.BackColor = dlgCommon.Color End Sub

  8. Updated Colorful Hello World • Allowing the user to change font styles ' Purpose: The Font dialog appears with the current options shown as defaults. ' Any changes made by the user are reflected in the message label. Private Sub mnuEditChangeFont_Click() dlgCommon.FontName = lblMessage.Font.Name dlgCommon.FontBold = lblMessage.Font.Bold dlgCommon.FontItalic = lblMessage.Font.Italic dlgCommon.FontSize = lblMessage.Font.Size dlgCommon.Color = lblMessage.ForeColor dlgCommon.FontStrikethru = lblMessage.Font.Strikethrough dlgCommon.FontUnderline = lblMessage.Font.Underline dlgCommon.Flags = cdlCFScreenFonts ' install fonts to show in list box ' see below to include color, strikethru & underline on font dialog dlgCommon.Flags = cdlCFEffects Or cdlCFScreenFonts Call dlgCommon.ShowFont lblMessage.Font.Name = dlgCommon.FontName lblMessage.Font.Bold = dlgCommon.FontBold lblMessage.Font.Italic = dlgCommon.FontItalic lblMessage.Font.Size = dlgCommon.FontSize lblMessage.ForeColor = dlgCommon.Color lblMessage.Font.Strikethrough = dlgCommon.FontStrikethru lblMessage.Font.Underline = dlgCommon.FontUnderline End Sub

  9. Updated Colorful Hello World • Allow the user to view a different picture ' Purpose: The File open dialog appears to allow the user to select a new ' image for the form. Private Sub mnuFileChangePicture_Click() dlgCommon.Flags = cdlOFNFileMustExist' file must exist flag dlgCommon.DefaultExt = ".gif" ' default extension .gif dlgCommon.Filter = "Picture (*.gif)| *.gif" ' filter show the files ' customize the title bar of the dialog box dlgCommon.DialogTitle = "OPEN--Please select new picture file” Call dlgCommon.ShowOpen imgFlag.Picture = LoadPicture(dlgCommon.FileName) End Sub

  10. Use Error Handler in Hello World • Make the Flags property assignment line a comment ' Purpose: The File open dialog appears to allow the user to select a new ' image for the form. Private Sub mnuFileChangePicture_Click() On Error GoTo ErrHandler ' dlgCommon.Flags = cdlOFNFileMustExist ' file must exist flag dlgCommon.DefaultExt = ".gif" ' default extension .gif dlgCommon.Filter = "Picture (*.gif)| *.gif" ' filter show the files ' customize the title bar of the dialog box dlgCommon.DialogTitle = "OPEN--Please select new picture file” Call dlgCommon.ShowOpen imgFlag.Picture = LoadPicture(dlgCommon.FileName) Exit Sub ErrHandler: Call MsgBox("Error #" & Err.Number & ": " & Err.Description, _ vbOKOnly + vbExclamation) End Sub

More Related