CommonDialog Control for Visual Basic 6.0 Users
The Visual Basic 6.0 CommonDialog control is replaced by several specialized components in Visual Basic 2008.
Conceptual Differences
In Visual Basic 6.0, the CommonDialog ActiveX control is used to display various common dialogs (Open, Save, Color, Font, Print, and Help) to your application.
In Visual Basic 2008, the CommonDialog control is replaced by individual components for displaying dialogs — the OpenFileDialog, SaveFileDialog, ColorDialog, FontDialog, and PrintDialog components.
Note
There is no direct equivalent for showing a Help dialog in Visual Basic 2008. The CommonDialog control only supported Windows Help; Visual Basic 2008 only supports HTML Help. Visual Basic 2008 uses the HelpProvider component to display help for your application. For more information, see Help Support for Visual Basic 6.0 Users.
Code Changes for the CommonDialog Control
The following examples illustrate the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008 for some common uses of the CommonDialog control.
Code Changes for Displaying a File Open Dialog Box
The following code demonstrates displaying a File Open dialog box, initialized to the Program Files directory.
' Visual Basic 6.0
' Uses a CommonDialog control.
CommonDialog1.InitDir = "C:\Program Files"
CommonDialog1.ShowOpen
' Visual Basic' Uses a OpenFileDialog component.
OpenFileDialog1.InitialDirectory = "C:\Program Files"
OpenFileDialog1.ShowDialog()
Code changes for Displaying a File Save Dialog Box
The following code demonstrates displaying a File Save dialog box, saving the file to the application's folder.
' Visual Basic 6.0
' Uses a CommonDialog control.
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowSave
' Visual Basic' Uses a SaveFileDialog component.
SaveFileDialog1.InitialDirectory = My.Application.Info.DirectoryPath
SaveFileDialog1.ShowDialog()
Code changes for Displaying a Print Dialog Box
The following code demonstrates displaying a Print dialog box, printing a file located in the application's folder.
' Visual Basic 6.0
' Uses a CommonDialog control.
CommonDialog1.FileName = App.Path & "MyFile.txt"
CommonDialog1.ShowPrinter
' Visual Basic' Uses PrintDocument and PrintDialog components.
PrintDocument1.DocumentName = My.Application.Info.DirectoryPath _
& "MyFile.txt"
PrintDialog1.Document = PrintDocument1
PrintDialog1.ShowDialog()
Code changes for Displaying Help
The following code demonstrates displaying a Help file from your application, opening it to the table of contents.
' Visual Basic 6.0
' Uses a CommonDialog control.
CommonDialog1.HelpFile = "C:\Windows\Help\calc.hlp"
CommonDialog1.HelpCommand = cdlHelpContents
CommonDialog1.ShowHelp
' Visual Basic' Uses the Help.ShowHelp method.
Help.ShowHelp(Me, "file://C:\Windows\Help\calc.chm", _
HelpNavigator.TableOfContents)
CommonDialog Control Property and Method Equivalencies
The following tables list Visual Basic 6.0 properties and methods and their Visual Basic 2008 equivalents. Properties and methods with the same names and behaviors are not listed. Where applicable, constants are indented beneath the property or method. All Visual Basic 2008 enumerations map to the System.Windows.Forms namespace unless otherwise noted.
Links are provided as necessary to topics explaining differences in behavior. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.
Properties
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Action |
New implementation. The Visual Basic 6.0 Action property determines which dialog to display; Visual Basic 2008 uses a separate component for each dialog. |
CancelError |
|
Copies |
|
DialogTitle |
Title (OpenFileDialog and SaveFileDialog components only) New implementation for the other components. Standard Windows titles (Color, Font, and Print) are displayed and cannot be overridden. |
FileName |
|
FileTitle |
New implementation. The Visual Basic 6.0 FileTitle property returns the FileName without the path; you can parse the FileNames property to get the name without the path. |
Flags |
The Visual Basic 6.0 Flags property provides constants for setting various attributes of the different common dialogs. Rather than using constants, the dialog components provide properties for setting the attributes. |
Font FontBold FontItalic FontName FontSize FontStrikethrough FontUnderline |
Note:
Fonts are handled differently in Visual Basic 2008. For more information, see Font Handling for Visual Basic 6.0 Users.
|
FromPage |
|
hDC |
New implementation. For more information see Graphics for Visual Basic 6.0 Users. |
HelpCommand |
|
HelpFile |
|
HelpKey |
The parameter parameter of the ShowHelp method. |
Index |
New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users. |
InitDir |
|
Left |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
Max |
MaxSize (FontDialog component) MaximumPage (PrintDialog component) |
Min |
MinSize (FontDialog component) MinimumPage (PrintDialog component) |
MaxFileSize |
New implementation. This property Visual Basic 6.0 allocates memory for extremely long file names; it is no longer necessary in managed code. |
Orientation |
|
Parent |
FindForm method |
PrinterDefault |
New implementation. This Visual Basic 6.0 property is used in conjunction with the hDC property to print using graphic device interface methods; this is no longer supported. |
Top |
P:System.Windows.Forms.Control.Top
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
ToPage |
Methods
Visual Basic 6.0 |
Visual Basic 2005 Equivalent |
---|---|
AboutBox |
New implementation. The AboutBox property displayed an About box for the CommonDialog control, which was created for Microsoft by a third party. |
ShowColor |
ShowDialog (ColorDialog component) |
ShowFont |
ShowDialog (FontDialog component) |
ShowHelp |
|
ShowOpen |
ShowDialog (OpenFileDialog component) |
ShowPrinter |
ShowDialog (PrintDialog component) |
ShowSave |
ShowDialog (SaveFileDialog component) |
Upgrade Notes
When upgrading an application from Visual Basic 6.0 to Visual Basic 2008, any CommonDialog controls are upgraded to their equivalent dialog component (OpenFileDialog, SaveFileDialog, ColorDialog, FontDialog or PrintDialog).
There is no direct equivalent for showing a Help dialog in Visual Basic 2008. If a CommonDialog control is being used as a Help dialog, a warning will be issued and it will not be upgraded. For more information, see Help Support for Visual Basic 6.0 Users.
A single CommonDialog control could be used to display different types of dialogs. In this case it will be upgraded to a OpenFileDialog component; a warning will be issued and you will need to add the other dialog components manually.
In addition, where a CommonDialog control was used as a variable you may need to change it to refer to a specific dialog component after upgrade.
See Also
Reference
FontDialog Component Overview (Windows Forms)
HelpProvider Component Overview (Windows Forms)
Other Resources
ColorDialog Component (Windows Forms)
OpenFileDialog Component (Windows Forms)
SaveFileDialog Component (Windows Forms)