473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PrintPreviewDialog Print Icon not printing

Hello all,
I'm trying to print using PrintPreviewDialog. What's happening is that the
PrintPreviewDialog shows the correct information to be printed, but when I
click the print icon, it prints a blank page. If I comment out the
printPreviewDialog1.ShowDialog();
and just do a
printDocument1.Print();
instead, it prints all the pages like a champ. Anyone know what I'm doing
wrong?
Thanks
Nov 15 '05 #1
2 5818
Randy,
As I said in my earlier reply you aren't resetting the start of the
print data stream (or wherever you get your print data from). You should
override the OnBeginPrint method of the PrintDocument and set your stream's
staring position back to the beginning there. If you have read through the
stream once already and don't reset the position when you press on the print
button on the PrintPreviewDialog you will already be at the end and thus
have nothing available to print.

Ron Allen
"Randy" <te**@temp.com> wrote in message
news:OF*************@TK2MSFTNGP11.phx.gbl...
Hello all,
I'm trying to print using PrintPreviewDialog. What's happening is that the
PrintPreviewDialog shows the correct information to be printed, but when I
click the print icon, it prints a blank page. If I comment out the
printPreviewDialog1.ShowDialog();
and just do a
printDocument1.Print();
instead, it prints all the pages like a champ. Anyone know what I'm doing
wrong?
Thanks

Nov 15 '05 #2
Try this print document class. Made it with my new tool.

I did exactly what you said - showed a print dialogue and hit the print
button and it's ok. If you're a VB developer, let me know and I'll reexport
it in VB.

//Code starts here

// GDIPlus Architect PrintDocument Class Output
// www.mrgsoft.com
public class Untitled1 : System.Drawing.Printing.PrintDocument {

// Current page
private int currentPage = 1;

// Total pages
private int totalPages = 2;

private System.Drawing.SolidBrush brush1 = new
System.Drawing.SolidBrush(System.Drawing.Color.Bla ck);

private System.Drawing.Font font1 = new System.Drawing.Font("Arial",
42.48F, ((System.Drawing.FontStyle)(0)), System.Drawing.GraphicsUnit.Point,
1);

private System.Drawing.StringFormat stringformat1 = new
System.Drawing.StringFormat(System.Drawing.StringF ormat.GenericTypographic);

protected string Text3 = "Hello world";

private System.Drawing.RectangleF Text3Rect = new
System.Drawing.RectangleF(136, 128, 426, 88);

protected string Text5 = "page 1";

private System.Single Text5PointX = 130;

private System.Single Text5PointY = 222;

protected string Text6 = "page 2";

private System.Single Text6PointX = 130;

private System.Single Text6PointY = 222;

public Untitled1() {
this.InitializeGraphics();
}

private void InitializeGraphics() {
this.stringformat1.Alignment = System.Drawing.StringAlignment.Near;
}

protected override void
OnPrintPage(System.Drawing.Printing.PrintPageEvent Args e) {
System.Drawing.Graphics g = e.Graphics;
this.printGraphics(g);
if ((this.currentPage < this.totalPages)) {
e.HasMorePages = true;
this.currentPage = (this.currentPage + 1);
}
else {
e.HasMorePages = false;
}
}

// Required to dispose of created resources
private void DisposeGraphics() {
this.brush1.Dispose();
this.font1.Dispose();
this.stringformat1.Dispose();
}

protected override void Dispose(bool disposing) {
if (disposing) {
this.DisposeGraphics();
}
}

private void printGraphics(System.Drawing.Graphics g) {
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias;
if ((this.currentPage == 1)) {
g.DrawString(this.Text3, this.font1, this.brush1,
this.Text3Rect, this.stringformat1);
g.DrawString(this.Text5, this.font1, this.brush1,
this.Text5PointX, this.Text5PointY);
}
if ((this.currentPage == 2)) {
g.DrawString(this.Text6, this.font1, this.brush1,
this.Text6PointX, this.Text6PointY);
}
}
}

"Randy" <te**@temp.com> wrote in message
news:OF*************@TK2MSFTNGP11.phx.gbl...
Hello all,
I'm trying to print using PrintPreviewDialog. What's happening is that the
PrintPreviewDialog shows the correct information to be printed, but when I
click the print icon, it prints a blank page. If I comment out the
printPreviewDialog1.ShowDialog();
and just do a
printDocument1.Print();
instead, it prints all the pages like a champ. Anyone know what I'm doing
wrong?
Thanks

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ramsey Schaffnit | last post by:
Context: I have to print personal information on a preprinted form I've never seen using a printer I've never seen. I want to use a control to overlay the PrintPreview to indicate where I've...
1
by: georg | last post by:
Hi, i have a problem with the PrintPreviewDialog, if i want to print out my document with the button in the preview dialog, the output on the printer is empty, but on the preview I can see it....
0
by: Harry J. Smith | last post by:
I am using the PrintPreviewDialog Window Form from the Toolbox. It displays my RichTextBox contents correctly, but when I click on the Print icon on this form it prints one blank page and no text....
1
by: gabriel | last post by:
Hi all, I've got a problem with a PrintPreviewDialog. It shows my document correctly but when I try to print I only get the last page. Now when I use the print function of my document directly...
1
by: Darrell Wesley | last post by:
Is there anyway to hook the PrintDialog to the printer icon on the PrintPreviewDialog? I know that you can print a document using the PrintDialog but it does not allow previewing and the...
10
by: choupi | last post by:
Hello, Is there a way to call a printDialog from a printPreviewDialog (from print icon for example)? Indeed, the print icon in the printpreviewdialog prints directly the document without...
0
by: tim8w | last post by:
I have the following PrintPreviewDialog code: Code: Private Sub tsbPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbPrintPreview.Click Dim...
0
by: sunny123 | last post by:
How Can i set the print icon in the printpreviewdialog to go to the printdialog? when I click on Report button in my application it'll open the report in print preview screen. There when I click...
0
by: mudapa03 | last post by:
In my application when I click on Report button report opens in Print Preview mode and when I click on print icon report directly send to the printer. Instead of that can I override the print icon...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.