If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[VB6] How Do I Work With The CommonDialog Control?

A: The CommonDialog control is used to add Windows' dialogs to your application. Dialogs you can add to your application include the following :

Open

Save

Print

Color

Fonts

Print

Help

Q: What is the benefit of using this CommonDialog control over creating your own?

A: The real benefit of using this component is that you get access to the built in dialogs provided by Windows, thus, creating consitency with all the other applications' look and feel

Q: How do I add this control to my form?

A: The easiest way is to right click on your tyoolbox, and to select Components... This will produce a box where you can select it. Scroll down until you find [b]Microsoft Common Dialog (Service pack version) Add a checkmark next to it and select OK. Just a note : Service pack will represent the current Visual Basic service pack you have instaled. So, if you have Service Pack 6 installed it will show 6.0. You will see the control gets added to your Toolbox. Double click it, and it is part of your Form. The CommonDialog control is actually a windowless control; this means that although you may see it during Design time, you will not see it appear on the form - you have to manipulate it through code, in order to show whichever dialog you want.

Q: How do I show the Open Dialog box?

A: Simple. Add the following code :

Code:

Private Sub Command1_Click()
CommonDialog1.ShowOpen
End Sub

This simply shows the Open dialog. It is actually ( at this moment ) not very useful, as it doesn't allow us to obtain whichever file was selected. The proper way to show the Open Dialog box is :

Code:

Private Sub Command1_Click()
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Label1.Caption = CommonDialog1.FileName
End If
End Sub

Here we just look at the FileName property of our COmmonDialog to establish a file selection. In case you expected the actual file to open, I have bad news This control doesn't physiaclly open the file for you, you still have to add the proper logic in order to achieve that. This just acts as a gateway to your files - that is all

The whole problem with the Help dialog is that you must have a help file already. In the above example I made use of Visual Basic's Help file.

Q: You mentioned something about the CommonDialog's Flags property earlier; can I have a list of all the various Flags we can set for the CommonDialog control?

A: Yes. Of course. I am attaching a list with this post.

Q: Is this all there is to the CommonDialog control?

A: For this example yes. But, there are many more setting you can set to further customise your commondialog control, and as you gain experience you will see them. I just made this simple introduction so that you can find your way further.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.