View contents of this chapter

Example

In this section we will develop an applicatioin that will show several dialog boxes. The source code needed for this example is stored in the
"Source Code\Chapter16" directory.

Private Sub cmdColor_Click()

   ' forces an error if user clicks cancel
   dlgCommon.CancelError = True
   On Error GoTo dlgErrHandler

   'set the color flags
   dlgCommon.Flags = cdlCCFullOpen

   'display the color dialog box
   dlgCommon.ShowColor

   'set the background color of the label
   lblTest.BackColor = dlgCommon.Color
Exit Sub   ' the regular procedure is done

   dlgErrHandler: ' the user clicked cancel
      Exit Sub
End Sub

Private Sub cmdFont_Click()
   ' forces an error if user clicks cancel
   dlgCommon.CancelError = True
   On Error GoTo dlgErrHandler

   'set the color flags
   dlgCommon.Flags = cdlCFBoth + cdlCFEffects

   'display the font dialog box
   dlgCommon.ShowFont

   'user selected font information
   lblTest.Font.Name = dlgCommon.FontName
   lblTest.Font.Size = dlgCommon.FontSize
   lblTest.Font.Bold = dlgCommon.FontBold
   lblTest.Font.Italic = dlgCommon.FontItalic
   lblTest.Font.Underline = dlgCommon.FontUnderline
   lblTest.Font.Strikethrough = dlgCommon.FontStrikethru
   lblTest.ForeColor = dlgCommon.Color

   dlgErrHandler:
      Exit Sub
End Sub

Private Sub cmdOpen_Click()
   'Returns or sets the filters that are displayed in the Typelist box
     'of a dialog box.

   dlgCommon.Filter = "Word Docs (*.doc)|*.doc|Excel Docs (*.xls)|*.xls"

    'display the File Open dialog box
   dlgCommon.ShowOpen
End Sub

Private Sub cmdPrint_Click()
    'display the print dialog box
   dlgCommon.ShowPrinter
End Sub

Private Sub cmdSave_Click()
   'display the File Save dialog box
   dlgCommon.ShowSave
End Sub

Play Sound

Today's lesson explained how you can set up common dialog to perform standard tasks. We used a special control called the Common Dialog Box control, which produces six different common dialog boxes.




© Universal Teacher Publications        INDEX Previous Screen Next Screen