Solved

Let user choose printer on print-buttom for PrintPreview

Posted on 2011-09-12
8
447 Views
Last Modified: 2013-12-17
Hi,

I need to print so sttuff from my application.
For this I use the printPreviewDialog control.
This works fine, only when the user press the print button now the output will ever be printed to the default printer.
Is there a way for to let the user select a printer when he pressed the button?
Or may be an other solution to change the printer for a printPreviewDialog?

Thanks

Andre
0
Comment
Question by:andre72
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Expert Comment

by:x77
ID: 36523623
Note that "Print Button" on printPreviewDialog  do:

   PrintDocument.Print

You can´nt alter this behaviour.

But PrintDocument allow you override some methods. On_BeginPrint
     Also you can suscribe Event. BeginPrint

   At this Point, you can call PrintDialog to get a PrinterSettings.
   If Dialog - Ok, Then set  Document.PrinterSettings to Dialog.PrinterSettings
   If Dialog - Cancel then set  e.Cancel = true - This abort action.
0
 
LVL 5

Expert Comment

by:Rainverse
ID: 36523671
2010 (Framework 4) allows this with the PrintDialog, however, this may help with earlier versions: http://www.vbdotnetheaven.com/UploadFile/DipalChoksi/WindowsForms04202005003607AM/WindowsForms.aspx
0
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
ID: 36524412
A brief full example to verify how change Printer on PrintPreviewDialog Print button.

Not. On this sample, I test also change orientation on PrintDialog. It works fine.
Imports System.Drawing.Printing
Public Class Form1

    Private WithEvents Pd As PrintDocument
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Pd = New PrintDocument With {.OriginAtMargins = True}
        Dim dlg As New PrintPreviewDialog With {.Document = Pd}
        dlg.ShowDialog()
        Pd = Nothing
    End Sub

    Private Sub Pd_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Pd.BeginPrint
        If Pd.PrintController.IsPreview Then Return 'Avoid Printdialog when Preview
        Dim dlg As New PrintDialog With {.Document = Pd}
        If dlg.ShowDialog = Windows.Forms.DialogResult.Cancel Then e.Cancel = True
    End Sub

    Private Sub Pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Pd.PrintPage
        e.Graphics.DrawString("prueba - Solo Una Página", Font, Brushes.Black, 0, 0)
        e.HasMorePages = False
    End Sub
End Class

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36526279
>Is there a way for to let the user select a printer when he pressed the button?

Yes. Show them a print dialog

http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:Rainverse
ID: 36526369
That's framework 4 only, correct?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36526378
0
 
LVL 15

Expert Comment

by:x77
ID: 36526443
I use PrinDialog since Net 1.1.

But this question is about show PrintDialog when user Press the Print Button on PrintPreviewDialog.


Image1.jpg
0
 

Author Closing Comment

by:andre72
ID: 36529732
Yes you're right - I wrote about this button :-)
Thanks for your support
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now