common print dialog

reddragon105
02-27-2002, 04:43 AM
i have an option to print something

when you click on the print button the print dialog comes up, allowing you to choose the printer, what pages to print and how many copies etc.

if you click ok, it goes ahead and prints, the problem is, if you click cancel it prints anway

how do i take the response from the print dialog? so that i can print if the user clicks ok, and nothing happens if they click cancel

Ales Zigon
02-27-2002, 04:49 AM
Set CancelError to TRUE. Like this:
On Error GoTo cancelprint
CommonDialog1.CancelError = True
'your code here
Exit Sub
: cancelprint
'cancel button was pressed do nothing

Flyguy
02-27-2002, 04:51 AM
Set the .CancelError property of the CommonDialog control to True. This will raise an error which can be trapped.

Sub WhatEver()
On Error Goto errHandler

CommonDialog.CancelError = True
CommonDialog.ShowPrinter
' your code

Exit Sub

errHandler:
Select Case Err.Number
Case 32755
' user pressed Cancel
Case Else
' other error occured
End Select
End Sub

divil
02-27-2002, 05:05 AM
Alternatively (avoids a GoTo):


On Error Resume Next
cd.ShowPrint()
If Err Then Exit Sub

'Continue with the printing here

Flyguy
02-27-2002, 05:16 AM
Divil you are correct, but this my general error handling method. I'm glad the way errors have to be handled in VB.Net is different!

divil
02-27-2002, 06:22 AM
Me too, although the common dialogs work slightly differently too:


Dim myResult As System.Windows.Forms.DialogResult

myResult = OpenFileDialog.ShowDialog()
If myResult = DialogResult.Cancel Then Exit Sub

'Perform opening code

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum