473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

PrintDialog opens twice in windows.forms problem

Spitaki
Hi,

When I call the sub Print the PrintDialog opens twice. What do I have to change so this won't happen again? When I call the sub PrintPreview it works just fine. Has anyone an idea what I do wrong?

Thanks in advance for your help.


Public Sub Print()
Try
Dim dlgPrint As New PrintDialog()
dlgPrint.Document = PrintDocument1
dlgPrint.PrinterSettings.Copies = Me.txtNumberOfCopies.Text

Dim result As DialogResult
result = dlgPrint.ShowDialog()

If result = System.Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
Catch ex As Exception
MessageBox.Show("An error occurred printing the file - " + ex.Message)
Finally

End Try

End Sub

Public Sub PrintPreview()
Try
Dim dlgPreview As New PrintPreviewDialog()
dlgPreview.Document = PrintDocument1
dlgPreview.WindowState = FormWindowState.Maximized

If dlgPreview.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Throw ex
End Try
End Sub
Mar 20 '07 #1
3 1833
radcaesar
759 Expert 512MB
Debug and find the first instance and the second instance in the code where you call those methods.

Use break points and debug line by line. Its hard to find with these amount of code.

:)
Mar 20 '07 #2
Found the problem!

I had a addhandler in the code so the print sub was called twice.... oops...
Mar 20 '07 #3
kenobewan
4,871 Expert 4TB
Well done! Thanks for sharing the solution.
Mar 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: aimee | last post by:
Hi. Is there a way to capture the events fired in a PrintDialog? I would like to capture when the user presses "Print" so I can do some cleanup. The asp.net (IE6) application I'm working on has 6...
2
by: David | last post by:
Does anybody know how to check the AllowSelection radio button in the PrintDialog Dialog? I want to set this to checked if the user has selected a subset of text.
1
by: mphanke | last post by:
Hi, I wrote a userControl w/ a toolbar. One button is supposed to open the PrintDialog. When I use the control in a different project and click that button - the form simply closes and the...
1
by: Blaine | last post by:
When I show my Windows Form as a dialog box (ShowDialog(Me)) and click on a button that calls the ShowDialog of either the PageSetupDialog or PrintDialog conrtol, my Windows Form closes After I...
4
by: mafandon | last post by:
Is it possible to send a performclick to a button on a printdialog? I know you can do an if statement similar to: if windows.forms.dialogresult.cancel then msgbox("User cancelled print...
0
by: Stefan | last post by:
Dear all, I'm using VB 2005 Have a question regarding printdialog. I have to click at least twice the ok button to confirm printer selection. Any suggestions, Stefan
10
by: choupi | last post by:
Hello, Is there a way to call a printDialog from a printPreviewDialog (from print icon for example)? Indeed, the print icon in the printpreviewdialog prints directly the document without...
2
by: Artie | last post by:
Hi, I've searched the web but can't find a solution to an apparently really simple problem. My app contains an HTML string and I need to be able to invoke the Print Dialog to print the HTML...
1
by: JR | last post by:
Dim PrintDialog As New PrintDialog Dim result As DialogResult = PrintDialog.ShowDialog() If result = Windows.Forms.DialogResult.OK Then 'I get always cancel(2) as an result and nothing happens...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.