Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Let user choose printer on print-buttom for PrintPreview

Posted on 2011-09-12
8
Medium Priority
?
465 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 2000 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Loops Section Overview

610 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