|
-
Sep 20th, 2002, 08:18 AM
#1
Thread Starter
Member
Common Dialogue OK
I am writting some code using the microsoft common dialog control 6.0 and need to have an action take place when someone clicks on open or cancel. How do you write code for an action when you click cancel or open?
Thanks
-
Sep 20th, 2002, 08:21 AM
#2
Frenzied Member
FROM MSDN
Visual Basic: CommonDialog Control
CommonDialog Control
The CommonDialog control provides a standard set of dialog boxes for operations such as opening and saving files, setting print options, and selecting colors and fonts. The control also has the ability to display help by running the Windows Help engine.
Syntax
CommonDialog
Remarks
The CommonDialog control provides an interface between Visual Basic and the routines in the Microsoft Windows dynamic-link library Commdlg.dll. To create a dialog box using this control, Commdlg.dll must be in your Microsoft Windows SYSTEM directory.
You use the CommonDialog control in your application by adding it to a form and setting its properties. The dialog displayed by the control is determined by the methods of the control. Atrun time, a dialog box is displayed or the help engine is executed, when the appropriate method is invoked; atdesign time, the CommonDialog control is displayed as an icon on a form. This icon can't be sized.
The CommonDialog control can display the following dialogs using the specified method.
Method Dialog Displayed
ShowOpen Show Open Dialog Box
ShowSave Show Save As Dialog Box
ShowColor Show Color Dialog Box
ShowFont Show Font Dialog Box
ShowPrinter Show Print or Print Options Dialog Box
ShowHelp Invokes the Windows Help Engine
The CommonDialog control automatically provides context sensitive help on the interface of the dialog boxes by clicking:
The What's This help button in the title bar then clicking the item for which you want more information.
The right mouse button over the item for which you want more information then selecting the What's This command in the displayed context menu.
The operating system provides the text shown in the Windows 95 (or later) Help popup. You can also display a Help button on the dialog boxes with the CommonDialog control by setting the Flags property, however, you must provide the help topics in this situation.
Note There is no way to specify where a dialog box is displayed.
For More Information To see help topics for each dialog, click on See Also.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Sep 20th, 2002, 08:26 AM
#3
Frenzied Member
VB Code:
Set the CommandDialog1's CancelError property to True
Private Sub Command1_Click()
On Error GoTo Hell:
CommandDialog1.ShowOpen 'Shows open dialog
Msgbox CommandDialog1.FileName 'Shows the selected file.. This code will only executed when Open is clicked
Exit Sub
Hell:
'This is where the control comes when user clicks Cancel Button
If Err.Number = 32755 Then 'U check to see if the error is one generated by the Cancel Button
''Code..
End If
End Sub
-
Sep 20th, 2002, 08:27 AM
#4
PowerPoster
Something like this:
VB Code:
Private Sub Form_Load()
'=======================
Dim strFileName As String
On Error GoTo ErrHanler
CD.ShowOpen
If Not CD.CancelError Then
strFileName = CD.FileName
End If
Exit Sub
ErrHanler:
'---------------
Debug.Print Err.Description
Err.Clear
Resume Next
End Sub
Roy
-
Sep 20th, 2002, 08:30 AM
#5
Thread Starter
Member
Thanks Swatty, great information!
Is there a way to have a second action take place when you click on a common diaglogue button, for example if you click on open can you also trigger the form to change color.
-
Sep 20th, 2002, 08:34 AM
#6
Frenzied Member
Yah Sure !!!
VB Code:
Set the CommandDialog1's CancelError property to True
Private Sub Command1_Click()
On Error GoTo Hell:
CommandDialog1.ShowOpen 'Shows open dialog
Me.BackColor = vbBlue '.. This code will only executed when Open is clicked
Exit Sub
Hell:
'This is where the control comes when user clicks Cancel Button
If Err.Number = 32755 Then 'U check to see if the error is one generated by the Cancel Button
''Code..
End If
End Sub
-
Sep 20th, 2002, 10:58 AM
#7
Thread Starter
Member
Where can I find info on Err.Number = 32755?
-
Sep 20th, 2002, 11:04 AM
#8
PowerPoster
In general, it is not a good practce to hardcode an error number (or anything at all if can be avoided). Instead use (as much as you can) generic Error Handling routine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|