1
votes

Here is the code I use (just the printing-related part):

Button 1 onclick handler method:

printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    PrintDocument pd = new PrintDocument();
    pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
    pd.PrinterSettings.PrintToFile = true;
    pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    pd.Print();
}

And my pd_PrintPage method:

Bitmap bitmapCanvas = new Bitmap(1000, 1000);
Graphics g = Graphics.FromImage(bitmapCanvas);
g.Clear(Color.White);
...
some g.Draw...() stuff

...
e.Graphics.DrawImage(bitmapCanvas, A(2), A(2));
//where e is the PrintPageEventArgs defined in the method signature

First part of my problem is that, this doesn't print to the selected printer (selected on the print dialog). It only prints to a printer if that is the default printer. Under Windows 7 it works, it recognizes the default printer, so the default printer will be selected by default in the comboBox on the print dialog which comes up after I click the button.

My main problem is that, this doesn't work under Windows Xp at all (unfortunately I only can use that). And I'm kind of curious why. So I don't know if I made a mess, or it is not supported under Windows Xp.

With what should I complete or correct my code?

Any help is appreciated and thank you very much! Mitulat bati

1
What were you expecting? Use the PrinterSettings property. - It'sNotALie.
What do you think I was expecting? What properties should I set to reach my aim? - Mitulát báti
What I told you to use, PrintDocument.PrinterSettings. - It'sNotALie.
You create the PrintDialog but then never use it, when you are editing your paper size you would want to operate on the printDialog1.Document Property you just create a new one which is likely to use your default printer. - Bearcat9425
newStackExchangeInstance: PrinterSettings is a class which has properties. My question was about those properties... but I think now I see it. Thank you! - Mitulát báti

1 Answers

0
votes

Try this,

printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    printDialog1.Document.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
    printDialog1.Document.PrinterSettings.PrintToFile = true;
    printDialog1.Document.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    printDialog1.Document.Print();
}