Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Howto use PrintPreviewControl

Posted on 2008-10-21
11
Medium Priority
?
2,706 Views
Last Modified: 2012-05-05
I have an application that prints invoices but before printing the user should be able to print preview each invoice in a printpreviewcontrol.
I have a printpreviewcontrol and a printdocument control on my form. I set the document of the printpreviewcontrol to printdocument1. When I call printdocument1.print function it prints on a file not on the preview control. How can I make it to print on the preview control?



ppc_invoice.Document = PrintDocument1
PrintDocument.Print

Open in new window

0
Comment
Question by:emresamisuzer
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22766780
See if this article helps...

Print Dialogs  
http://www.startvbdotnet.com/controls/printdialog.aspx

Hint:  The Print method prints--period.
0
 

Author Comment

by:emresamisuzer
ID: 22776354
It writes the following code but it doesn't work for me.

Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MenuItem5.Click
Try
PrintPreviewControl1.Document = PrintDocument1
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22776408
How are you creating the PrintDocument?  Are you handing the PrintPage event?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:emresamisuzer
ID: 22776566
The printdocument is created at design time (dragged from the toolbox). It has the printpage event and if I call printdocument1.printpage it prints to a paper.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22776649
Ok, what does the PrintDocument_PrintPage event handler look like?  I am not suggesting using the Print method, since I told you that will send the output to the printer.
0
 

Author Comment

by:emresamisuzer
ID: 22776819
The fonts and locations are from a dataset, but the printpage events is not triggered.
 e.Graphics.DrawString("TEST", fonts(dr("id_font")), Drawing.Brushes.Black, CInt(dr("x")), CInt(dr("y")))

Open in new window

0
 

Author Comment

by:emresamisuzer
ID: 22776849
Sorry, you asked the handler
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22776922
If you drop a PrintDocument and PrintPreviewControl on a form, and set the PrintPreviewControl.Document property, and you have code in the PrintPage event handler, you should get a document on the PrintPreviewControl.

Example:


Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
  e.Graphics.DrawString("This is a test", Me.Font, Brushes.Red, New PointF(50, 50))
End Sub

Open in new window

0
 

Author Comment

by:emresamisuzer
ID: 22795225
I am using WeifenLuo dockpanel, I think it somehow blocks the print_page event?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 22796520
Try creating another test form, and see how the controls work together, to make sure that the DockPanel is what is the culprit.
0
 

Author Comment

by:emresamisuzer
ID: 22797430
Yes, the dockpanel is the reason. Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

972 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