Urgent PrintPreview Error?

A

Adam Right

Hi,

I am using .Net Framework 2.0 final, and i use .Net printing library to
print a document. I use printPreview dialog to print the document but after
preview was shown, when i press the "print" button, i cannot print the
document although there is some words on the preview. So, is there a bug in
the preview?

Thanks...
 
Z

Zanna

"Adam Right" <[email protected]> ha scritto nel messaggio

I am using .Net Framework 2.0 final, and i use .Net printing library to
print a document. I use printPreview dialog to print the document but after
preview was shown, when i press the "print" button, i cannot print the
document although there is some words on the preview. So, is there a bug in
the preview?

did you detach the PrintDocument events?

Do you get an exception or the document simply is not printed?
 
A

Adam Right

Hi,

My code is on the below,

m_PrintDocument = new PrintDocument( );
m_PrintDocument.PrintPage += new PrintPageEventHandler(
m_PrintDocument_PrintPage );
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog ( );
printPreviewDialog1.Document = m_PrintDocument;
Form m_Temp = ( Form ) printPreviewDialog1;
m_Temp.WindowState = FormWindowState.Maximized;
printPreviewDialog1.ShowDialog ( );

void m_PrintDocument_PrintPage( object sender, PrintPageEventArgs e )
{
Font printFont = new Font ( "Courier" , 10 , FontStyle.Regular );
String myString = "Trying";
e.Graphics.DrawString( myString, printFont, Brushes.Black, 0, 0, new
StringFormat( ) );
}
 
Z

Zanna

Adam Right said:
Hi,

My code is on the below,

[Snip]


This works perfect to me:
class Printer {

public void Print()

{

PrintDocument m_PrintDocument = new PrintDocument();

m_PrintDocument.PrintPage += new
PrintPageEventHandler(m_PrintDocument_PrintPage);

PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();

printPreviewDialog1.Document = m_PrintDocument;

Form m_Temp = (Form)printPreviewDialog1;

m_Temp.WindowState = FormWindowState.Maximized;

printPreviewDialog1.ShowDialog();

}

void m_PrintDocument_PrintPage( object sender, PrintPageEventArgs e )

{

Font printFont = new Font ( "Courier" , 10 , FontStyle.Regular );

String myString = "Trying";

e.Graphics.DrawString( myString, printFont, Brushes.Black, 0, 0, new

StringFormat( ) );

}

}
 
A

Adam Right

Hi,

I think so, but i cannot use the printpreview print button to print the
document. It gives me an empty page although there is some words in the
document. It works fine before i installed .Net 2.0 final. Is it about
framework?

Zanna said:
Adam Right said:
Hi,

My code is on the below,

[Snip]


This works perfect to me:
class Printer {

public void Print()

{

PrintDocument m_PrintDocument = new PrintDocument();

m_PrintDocument.PrintPage += new
PrintPageEventHandler(m_PrintDocument_PrintPage);

PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();

printPreviewDialog1.Document = m_PrintDocument;

Form m_Temp = (Form)printPreviewDialog1;

m_Temp.WindowState = FormWindowState.Maximized;

printPreviewDialog1.ShowDialog();

}

void m_PrintDocument_PrintPage( object sender, PrintPageEventArgs e )

{

Font printFont = new Font ( "Courier" , 10 , FontStyle.Regular );

String myString = "Trying";

e.Graphics.DrawString( myString, printFont, Brushes.Black, 0, 0,
new

StringFormat( ) );

}

}
 
Z

Zanna

I think so, but i cannot use the printpreview print button to print the
document. It gives me an empty page although there is some words in the
document. It works fine before i installed .Net 2.0 final. Is it about
framework?

I used the code I wrote with VS.Net 2005, so, against fw 2.0 final.

Did you tryied my code (that, after all is your) simply using:

Printer p = new Printer();
p.Print();

?

When I print the page it is printed correctly.
 
A

Adam Right

Hi,

Do you think that it is the solution? I think it cannot be accepted that the
print button of the printpreview form is not working although there are
words on the document. Is it a bug? The printpreview dialog must print the
document. What do you think really i wonder about it?
Thanks...
 
B

Bruce Wood

The problem is not that the document will not print correctly.

The problem is that using the Print... menu item from
PrintPreviewDialog causes it to be printed _twice_: once to display in
the print preview, then again to print on the printer. The document is
not printing properly the second time, when PrintPreviewDialog tries to
print it again to the printer.

So, your test is inadequate: you are only trying to print the document
once, using .Print().

We have another thread going on this problem. I suggest that we abandon
this discussion and concentrate on that other thread.
 
Z

Zanna

"Adam Right" <[email protected]> ha scritto nel messaggio

Do you think that it is the solution? I think it cannot be accepted that the
print button of the printpreview form is not working although there are
words on the document.

I really don't understand.
The code I posted is working or not?

If it is working where is the problem?
 
A

Adam Right

Hi,

Ok, i can use Print() function to print the document but i have to show the
documents that will be printed to the user. The reason is that user may or
not print the document he/she has to see the document. So by using Print()
function how can i show the print document either?
Thanks...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top