Solved

Let user choose printer on print-buttom for PrintPreview

Posted on 2011-09-12
8
451 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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