Solved

Let user choose printer on print-buttom for PrintPreview

Posted on 2011-09-12
8
452 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
DevOps Toolchain Recommendations

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

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write to a printer using vb.net 9 38
Call Controller Action Method from ASPX 2 22
VB.NET 2008 - SQL Timeout 9 34
Release Dynamically Allocated Memory in C# 3 38
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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