Results 1 to 5 of 5

Thread: CommonDialog and printing

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Geelong, Victoria, Australia
    Posts
    8
    Using the CommonDialog control to display a Print dialog, how do you determine whether the user has clicked 'Cancel' or 'OK'. (i.e. Nothing should print if they hit cancel.)
    Stu.

  2. #2
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    The way I would do it, which isn't usually the most efficient is to use this code if you are using a command button to print the file:
    Code:
    Private Sub cmdPrint_Click()
      On Error GoTo errorline 'skip the commondialog code
      'your commondialog code here
      Exit Sub 'exit the sub incase they pressed OK
      errorline: 'declare the error line
      msgbox "You canceled the print command..." 'you can delete this msgbox code
                                                 'and nothing will happen when the button
                                                 ' is pressed, like most programs.
    End Sub
    <removed by admin>

  3. #3
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    If you're using the common dialog control, set its CancelError property to true, then you can check the Err object. If you hit a cancel button in the common dialog with CancelError = True, Err.Number = cdlCancel. This is a better way to check it since you won't catch every single error at once, only the cancel one (although you should check for general errors too). If that seems clear as mud, here's a little snip from an open command in a prog of mine:
    Code:
    Public Sub OpenFile()
    
       Dim FileName As String
    
       mdiText.dlgDialog.DialogTitle = "Open File"
       mdiText.dlgDialog.Flags = cdlOpenFileFlags
       mdiText.dlgDialog.Filter = cdlFilter
       mdiText.dlgDialog.FilterIndex = 1
       mdiText.dlgDialog.CancelError = True
    
       On Error Resume Next
    
       mdiText.dlgDialog.ShowOpen
    
       'specific check for the Cancel button being pressed
       If Err.Number = cdlCancel Then Exit Sub
    
       FileName = mdiText.dlgDialog.FileName
    
       'resume with normal events of program since there was a valid filename selected
    Hope this helps you.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  4. #4
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    Here's a simple way that I used to print and was able to cancel the printing when the cancel button was clicked.

    Private sub mnuFilePrint_Click()
    on local error goto printerror
    commondialog1.cancelerror = true
    commondialog1.flags = cdlpdallpages + cdlpdreturndc
    commondialog1.showprinter

    'put what needs to be printed here.

    printerror:
    printer.enddoc
    end sub

    hope this helps.

  5. #5
    Guest

    Importan !!!!!!!!!!!!!!!!!

    Hi

    You can forget to use the common dialog for printer change!!!!!!!!!!!!
    Microsoft have a big bug in this control!!! because if you change any property of the printer with the common dialog it will be ignorred!!.

    If you want you can have an class modul from me. It work with api- calls and you don't need the common dialog control.

    send me a mail to [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width