I do not find Commnon Dialog Control in the toolbox,Can somebody plz tell me from where to drag the control? I have just General Tab in my toolbox????

Recommended Answers

All 11 Replies

the common dialog control is an intrinsic control. it cannot be displayed in your toolbox by default. you have to manually add it.

please goto Project->Components

then select Microsoft Common Dialog Control 6.0

click Apply->Ok
Now you can see it on your toolbox

regards
Shouvik

add it on component.
ctrl + T (or right click on your toolbox / project->component) -> check for Microsoft Common Dialog Control 6.0 -> OK
it will shown on your toolbox.

Below is the code for Color Dialog Box-
On Error GoTo errortrap
CommonDialog1.Action = 3
Form1.BackColor = CommonDialog1.Color
Exit Sub
errortrap:
MsgBox "dialog box is canceled"

CAN somebody tell me that how we know,That colorDilag Box has number 3,Print dialog Box has no 5.

And even 4 colors,like the foll. statement changes the backcolor if form to the desired color-form1.backcolor=QBcolor(2)
2 no is for Green Color.

We have to grap these numbers.??

there is no need to use the Action property.

use .ShowColor like

'for color dialog
CommonDialog1.ShowColor
'for print dialog
CommonDialog1.ShowPrinter
'for openfile dialog
CommonDialog1.ShowOpen
'for save as dialog
CommonDialog1.ShowSave

for changing color of the form this line
Form1.Backcolor=Commondialog1.Color
is perfectly ok

and for trapping the error when you press cancel button in the dialog do like this ,

Commondialog1.CancelError=False

hope this helps

regards
Shouvik

This method is also working. Secong thing,u have done one error ,to detect an error during the display of the dialog Box, Set the CancelError property of the common Dialog Control to True not False.

But the method i have used initially was also working fine.U don't know from where to see that numbers...... U didn't have used dat method.

is there any condition you have in your project that you must use the .Action property?
if yes then there is nothing to say. but if not then why are you using that technique? because using the .Show<Dialog Name> is most preferable than using the .Action method as in the later case you have to remember those numbers. but if you use the former one you don't need to remember anything. each one of them will be available to you just when you call the intellisense.

ok... if you insist so then these are the numbers for your action property :-

for openfile dialog
Action=1
for save as dialog
Action=2
for color dialog
Action=3
for fonts dialog
Action=4
for printer dialog
Action=5

one more thing, regarding the error you just misjudged what i've said. the syntax for error trapping which i gave is for preventing an error to be displayed when an user clicks cancel button of the dialog not to show the error.

if you set CancelError=True and you click the cancel button vb6 will return you the following runtime exception :-

Runtime Error : 32755
Cancel was selected

now if you click on the debug button the compiler will highlight this line (based on which dialog you opened) :-
CommonDialog1.ShowOpen

so in this case you must write an error handler explicitly. now to avoid this from happen you can set CommonDialog1.CancelError = False. for this you don't have to write an error handler and of course the compiler also won't return you any runtime exception whenever you click on the cancel button.

i think you will be on your way now
ok...

regards
Shouvik

Secong thing,u have done one error ,to detect an error during the display of the dialog Box, Set the CancelError property of the common Dialog Control to True not False.

why are you trying to display runtime error from your application? will it add extra values to your project? or will it enhance good looks for your application?

never mind but as a programmer/developer every one tries to make bug/error free application. that's the optimum requirement in software development.

must be you are in opposite path!!!

No if set CancelError propert to false,Then when the user clicks on CANCEL button,BavkVColor of the from is changed to BLaCk volor.

Now set the Cancelerror property to True & write the foll. Code-

Private Sub Command1_Click()
On Error GoTo errortrap
CommonDialog1.ShowColor

Form2.BackColor = CommonDialog1.Color
Exit Sub
errortrap:
MsgBox "Dialog Box is cancelled"
End Sub

Now when the use clickk on Cancel Msgbox is displayed "DIALOG BOX IS CANCELLED".

According to me,it would look more appropriate.

ok.....that's a separate issue.
in that case your assumption is correct.

i just posted it because you didn't tell that first.

regards
Shouvik

Go to project and then select the components and then check the M/S common dialog control 6.0

Go to project and then select the components and then check the M/S common dialog control 6.0

if i'm not wrong that thing is already done in previous replies.
he has also started coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.