PrinterSetting are ignored while printing an Image
I'm trying to print an Image using PrintDocument
in C# but somehow the setting (like Number of Pages and Image Quality ) are ignored while printing and preview.
Is there anything wrong in following code, Am I missing something?
private void button1_Click(object sender, EventArgs e)
{
using (var printDialog = new PrintDialog())
{
if (printDialog.ShowDialog() == DialogR开发者_StackOverflow社区esult.OK)
{
_printDocument.PrinterSettings = printDialog.PrinterSettings;
}
}
}
void _printDocument_Print(object sender, PrintPageEventArgs e)
{
using (Image image = new Bitmap("image0002.tif"))
{
e.Graphics.DrawImage(image, e.MarginBounds.X, e.MarginBounds.Y);
}
}
Have you tried setting the PrintDialog
's Document
property to the document you want to print? The dialog should automatically manage the settings for the current PrintDocument
if I remember correctly, so there should be no need to manually assign the PrinterSettings
.
In addition, I think that a DialogResult.OK
from PrintDialog.ShowDialog()
means that you should print the document (the user clicked the 'Print' button).
For example:
using (var printDialog = new PrintDialog { Document = _printDocument })
{
if (printDialog.ShowDialog() == DialogResult.OK)
{
_printDocument.Print();
}
}
Does that help?
EDIT: If you don't want to print right away, you could try:
using (var printDialog = new PrintDialog { Document = _printDocument })
{
printDialog.ShowDialog();
}
but users might find it a little strange if they click 'Print' and the document doesn't print.
精彩评论