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.
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.
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.
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
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
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
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
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.
Visual Basic 6.0
Visual Basic 2008 Equivalent
New implementation. The Visual Basic 6.0 Action property determines which dialog to display; Visual Basic 2008 uses a separate component for each dialog.
New implementation for the other components. Standard Windows titles (Color, Font, and Print) are displayed and cannot be overridden.
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.
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.
Fonts are handled differently in Visual Basic 2008. For more information, see Font Handling for Visual Basic 6.0 Users.
New implementation. For more information see Graphics for Visual Basic 6.0 Users.
The parameter parameter of the ShowHelp method.
New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users.
MaximumPage (PrintDialog component)
MinimumPage (PrintDialog component)
New implementation. This property Visual Basic 6.0 allocates memory for extremely long file names; it is no longer necessary in managed code.
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.
Visual Basic 6.0
Visual Basic 2005 Equivalent
New implementation. The AboutBox property displayed an About box for the CommonDialog control, which was created for Microsoft by a third party.
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.