Common Dialog Control

Tips >> Visual Basic

MAKE WEB APPLICATION WITHOUT KNOWLEDGE OF CODING? CLICK HERE

WANTS TO MAKE SOFTWARE WITHOUT KNOWLEDGE OF PROGRAMMING? CLICK HERE 

The Common Dialog Control provides a standard interface for operations such as opening, saving, and printing files or selecting colours and fonts using the Microsoft Windows dynamic link library COMMDLG.DLL. The Control is visible on the form as an icon at design-time but not at run-time. The icon cannot be resized on the form and it's not possible to specify where the Dialog will be displayed when opened. To use a Common Dialog Control, add "Microsoft Common Dialog Control" from the "Project", "Components" menu item. The three-letter mnemonic for a Common Dialog Control is "cdl". The Control's Methods are used to determine which dialog is displayed.

SHOWCOLOR

The ShowColor method is used to display the Colour dialog box.

The Color property is used to determine which colour was selected.

cdlColour.ShowColor
picPallette.FillColor = cdlColour.Color

 

Alternatively, you may wish to break out the long number into its "Red", "Green" and "Blue" parts.

Dim Red As Long, Green As Long, Blue As Long
cdlColour.ShowColor
Red = cdlColour.Color And &HFF
Green = (cdlColour.Color \ &H100) And &HFF
Blue = cdlColour.Color \ &H10000

 

 

SHOWFONT:

The ShowFont method is used to display a list of fonts that are available. Before the ShowFont method can be displayed, the Flags property must be set to one of the following constants or a Message Box is displayed with a message of "There are no fonts installed", and a run-time error occurs.

  • cdlCFScreenFonts
  • cdlCFPrinterFonts
  • cdlCFBoth
' Set default values for Font
cdlFont.FontName = lblSurname.FontName
cdlFont.FontSize = lblSurname.FontSize
cdlFont.Flags = cdlCFScreenFonts
cdlFont.ShowFont
lblSurname.FontName = cdlFont.FontName
lblSurname.FontSize = cdlFont.FontSize

 

 

SHOWHELP:

The ShowHelp method is used to display a Windows Help File. You can write your own help files using the "Help Workshop" and display them with the Common Dialog Control's ShowHelp method. The HelpFile and HelpCommand properties must be set in order for the Help file to be displayed.

Help files are compiled files that are run using Winhlp32.exe. The Help Workshop that is part of the Visual Studio suite can be used to create Help files. The topics are written as Rich Text Format .rtf files. These are linked with other resources such as bitmaps into a single help file. The Help Workshop enables you to edit the project and contents files, and compile and test the help files.

The contents file is an ASCII text file, extension .cnt, that provides the instructions for the Contents tab in the Help Topics dialog box, and directs WinHelp to display the keywords of specified Help files on the Index and Find tabs. The contents file specifies the Headings, Topics, and Commands.

Headings contain a group of related topics and other Headings and is shown as a Book Icon. Topics display a topic of execute a macro and is shown as a page icon. The Commands specify the name of the default help file, title, the names of help files to be included on the Find tab and the names of help files containing keywords for KLink and ALink macros.

cdlHelp.HelpFile = "c:\juicystudio\tutorial.hlp"
cdlHelp.HelpCommand = cdlHelpContents
cdlHelp.ShowHelp
SHOWOPEN:

The ShowOpen method is used to display the dialog to open files. The FileName Property is used to determine the name of the file the user selected.

The Filter Property is used to determine the types of file to be shown. A Pipe symbol, |, is used to separate the description and value.
cdlOpen.Filter = "Text (*.txt)|*.txt"

 

Further filters may be specified on the same line separated by the Pipe symbol.

The following example uses a Common Dialog Control to allow either Text or Picture files to be selected.

Dim pattern As String
pattern = "Text (*.txt)|*.txt"
pattern = pattern & "|Pictures (*.bmp;*.gif;*.jpg)"
pattern = pattern & "|*.bmp;*.gif;*.jpg"
cdlOpen.Filter = pattern
cdlOpen.ShowOpen
picViewer.Picture = LoadPicture(cdlOpen.FileName)

 

 

SHOWPRINTER:

The ShowPrinter method is used to display the dialog to open files.

The following example uses the ShowPrinter method with the Printer object to set the number of copies and page orientation.

cdlPrinter.ShowPrinter
Printer.Copies = cdlPrinter.Copies
Printer.Orientation = cdlPrinter.Orientation
Printer.EndDoc

 

 

SHOWSAVE:

The ShowSave method looks exactly the same as the ShowOpen method, except the default title is "Save As" rather than "Open".

The following example uses the ShowSave method with the FSO to write the URL https://www.juicystudio.com to a text file specified by the user.

Dim fso As New FileSystemObject
Dim txtStream As TextStream
cdlSave.ShowSave
Set txtStream = fso.CreateTextFile(cdlSave.fileName, True)
txtStream.WriteLine "https://www.juicystudio.com"
txtStream.Close
Set txtStream = Nothing
Set fso = Nothing

If you don't find what you are looking for. Please click here to submit your query, our experts will reply soon.
E-mail : sales@virtualsplat.com
Phone : +91-9892413501

+91-9967648641

+91-9967648641