我想在打印面板之前显示打印对话框,然后在打印文档中实现选定的选项。这些选项是像方向,副本数量,页面大小(leter,A4,A3,...)。我如何使用选定的optionS?我的代码现在就像我的Winforms C#项目中的以下内容:
PrintDocument document = new PrintDocument();
PrintDialog dialog = new PrintDialog();
private void button2_Click_1(object sender, EventArgs e)
{
dialog.Document = document;
if (dialog.ShowDialog() == DialogResult.OK)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
doc.Print();
}
else
{
MessageBox.Show("Print Cancelled!");
}
}
private void doc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Panel grd = splitContainer1.Panel2;
Bitmap bmp = new Bitmap(grd.Width, grd.Height, grd.CreateGraphics());
grd.DrawToBitmap(bmp, new Rectangle(0, 100, grd.Width, grd.Height));
System.Drawing.RectangleF bounds = e.PageSettings.PrintableArea;
float factor = ((float)bmp.Height / (float)bmp.Width);
e.Graphics.DrawImage(bmp, bounds.Left + 20, bounds.Top, bounds.Width -40, factor * bounds.Width);
}
字符串
实际上,上面的代码显示了打印对话框,但在打印页面中没有实现任何内容。
1条答案
按热度按时间pkbketx91#
要获取对话框窗口中的任何更改,您可以查看
PrintDialog
。然后您必须在doc.Print
行之前设置PrintDocument
中的更改,如下所示:字符串