我有一个 Windows 窗体应用程序,带有一个包含面板的简单 Windows 窗体。我已将面板大小设置为:560、579(以像素为单位),并以这种方式设置打印文档大小:
System.Drawing.Printing.PaperSize a = new System.Drawing.Printing.PaperSize("A5 (148 x 210 mm)", 584, 827);
printDocument1.PrinterSettings.DefaultPageSettings.PaperSize = a;
现在我希望 printpreviewdialoge 页面大小为 a5 或至少与我的打印文档大小相同并适合它,我该如何实现?
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap b = new Bitmap(pnlPrint.Width, pnlPrint.Height);
pnlPrint.DrawToBitmap(b, new System.Drawing.Rectangle(0, 0, pnlPrint.Width, pnlPrint.Height));
e.Graphics.DrawImage(b,0,0);
}
private void Print()
{
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
var paperSize = printDocument1.PrinterSettings.PaperSizes.Cast<PaperSize>().FirstOrDefault(e => e.PaperName == "A5");
printDocument1.PrinterSettings.DefaultPageSettings.PaperSize = paperSize;
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}