472,141 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 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 5725
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by georg | last post: by
reply views Thread by Harry J. Smith | last post: by
1 post views Thread by gabriel | last post: by

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.