473,804 Members | 3,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PrintDialog opens twice in windows.forms problem

Spitaki
3 New Member
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.Docume nt = PrintDocument1
dlgPrint.Printe rSettings.Copie s = Me.txtNumberOfC opies.Text

Dim result As DialogResult
result = dlgPrint.ShowDi alog()

If result = System.Windows. Forms.DialogRes ult.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 PrintPreviewDia log()
dlgPreview.Docu ment = PrintDocument1
dlgPreview.Wind owState = FormWindowState .Maximized

If dlgPreview.Show Dialog = Windows.Forms.D ialogResult.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 1852
radcaesar
759 Recognized Expert Contributor
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
Spitaki
3 New Member
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 Recognized Expert Specialist
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
5932
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 pages, each of which has a link to a "print view" page. That "print view" page has a "print" button which calls a javascript function "printThis": function printThis() { alert('printThis')
2
3208
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
3877
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 application continues working? Any suggestions why this behavour occures??
1
2619
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 close the PageSetupDialog or PrintDialog. This doesn't happen if the Windows Form is displayed using the Show method. Does anyone have a solution? I've made my own Print Setup Dialog Box (frmPrint). I've added the PrintDocument, PageSetupDialog...
4
4947
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 option") end if But I would like to open the print dialog and automatically perform the "Print" button to save the user one more step.
0
758
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
15337
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 lunching the printdialog (i.e. the user can't choose the print parameters). Thanks a lot.
2
7601
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 correctly formatted (i.e. not as raw HTML) to a printer that the User chooses. So, I need something like:
1
4173
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 end if Why do I aways have cancel as an result. It shout popup but it doens on vista 64 Thanxs
0
9707
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9585
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10586
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.