100 likes | 355 Views
Common Dialog Boxes. Common Dialog Boxes. There are 5 types of Common Dialogs which share a single Common Dialog Control Use one of the following methods to define the operation Method What it Does Result found in Property
E N D
Common Dialog Boxes • There are 5 types of Common Dialogs which share a single Common Dialog Control • Use one of the following methods to define the operation Method What it Does Result found in Property ShowOpen File Open Dialog .filename or .filetitle ShowSave File Save Dialog.filename or .filetitle ShowColor Color Selection Dialog .color ShowFont Font Selection dialog .fontname, .fontsize, ... ShowPrinter Printer Selection dialog .printerdefault ShowHelp Help Dialog .helpcontext, .help...
Common Dialog Boxes (2) • The common dialog control has no associated events • Initialize the properties before invoking the Showxxx method • It is intended to be invoked with the dialogname.Showxxx method • Use On Error goto with the cancelerror property set to True to make the ESC key or Cancel Button abort the dialog • Use the with … end with construct to simplify and clarify code • Double Click (custom) for design time editor
Common Dialog Example On Error GoTo dialogerror: ' so that errors (or esc or cancel) end the box dlgOpenFile.InitDir = "C:\batch" ' the initial directory dlgOpenFile.filename="" ' no file (in case cancel is pressed) dlgOpenFile.CancelError = True ' cause an error if cancel button is pressed 'Filter spaces *ARE* significant - format is text1|mask1|text2|mask2... dlgOpenFile.Filter = "Executables (*.exe)|*.exe|Com files (*.com)|*.com|Batch file(*.bat)|*.bat" dlgOpenFile.FilterIndex = 3 ' choose the third filter item as the default dlgOpenFile.DialogTitle = "Choose a program to open" ' title of dialog dlgOpenFile.ShowOpen ' this is the open method dialogerror: ' go here if there's an error (or the ESC key pressed)
Common Dialog Example (2) With dlgOpenFile On Error GoTo dialogerror: ' so that errors (or esc or cancel) end the box .InitDir = "C:\batch" ' the initial directory .filename="" ' no file (in case cancel is pressed) .CancelError = True ' cause an error if cancel button is pressed 'Filter spaces *ARE* significant - format is "text1|mask1|text2|mask2…" .Filter = "Executables (*.exe)|*.exe|Com files (*.com)|*.com|Batch File(*.bat)|*.bat" .FilterIndex = 3 ' choose the third filter item as the default .DialogTitle = "Choose a program to open" ' title of dialog .ShowOpen ' this is the open method end with dialogerror: ' go here if there's an error (or the ESC key pressed)
Font Selection Dialog Box • Font Dialog Properties • color, fontbold, fontitalic, fontstrikethru, fontunderline, fontname, max, min, fontsize, flags, cancelerror • Useful Font Dialog Flags • 2 cdlCFPrinterFonts (printer fonts only) • 1 cdlCFScreenFonts (screen fonts only) • 3 cdlCFBoth (all screen & printer fonts) • 131072 cdlCFScalableOnly (Truetype fonts) • 32768 cdlCFWYSIWYG (both printer and screen) • 256 (enables font color selection)
Color Dialog Box • Color Dialog Properties • color, flags, cancelerror • Color Dialog Flags • 4 cdlCCPreventFullOpen (prevents user from defining own colors) • 2 cdlCCFullOpen (starts dialog with custom color window open)
Open File Dialog Box • OpenFile Dialog Properties • filename, filetitle, filter, filterindex, initdir, maxfilesize, flags, cancelerror • Openfile Dialog Flags • 512 cdlOFNAllowMultiSelect (allows selection of multiple files) • 4096 cdlOFNFileMustExist(user can only type in name of file that exists) • 2 cdlOFNOverwritePrompt(Prompts user for overwrite if file exists in SaveAs)
Print Dialog Box • Print Dialog Properties • Copies, frompage, max, min, printerdefault, topage, flags, cancelerror • Print Dialog Flags • 64 cdlPDPrintSetup (Displays printer setup dialog instead of the print options dialog) • 4 cdlPDNoSelection (Stops users from selecting print current selection) • 1048576 cdlPDHidePrintToFile (Hides Print to File option)
Custom Dialog Boxes • Really a form with the modal property set • You are free to use any type of control to customize it to your needs • Does require extra machine resources since it is another form • Often placed in a module so it can be used in a variety of forms - use the name main for the subroutine if you want it to start your application (as in a login process)