Solved

Let user choose printer on print-buttom for PrintPreview

Posted on 2011-09-12
8
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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