我正在尝试打印一些string
s using Graphicss.DrawString()
。我已将边距设置为printdocument
但不从页面的原点开始。我已经设定margins
to (0,0,0,0)
但不知怎的,它打印在页面顶部边缘下方半厘米处。另一件事是它可以从左边缘打印。
下面是我的代码。
private void button1_Click(object sender, EventArgs e)
{
////PaperSize pkCustomSize1 = new PaperSize("First custom size", 1020, 3517);
////printDocument1.DefaultPageSettings.PaperSize = pkCustomSize1;
printPreviewDialog1.Document = printDocument1;
printDocument1.PrinterSettings.PrinterName = this.comboBox1.Text;
Margins margins = new Margins(0, 0, 0, 0);
printDocument1.PrinterSettings.DefaultPageSettings.Margins = margins;
printPreviewDialog1.Show();
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int resX = GetPrinterResolutionX(comboBox1);
int resY = PrnOpra.GetPrinterResolutionY(comboBox1);
Graphics g = e.Graphics;
float scale = resX / ScrnRes;
Bitmap bm = new Bitmap(367, 1205);
g.DrawRectangle(new Pen(Color.Black, 0.5F), panel9.Location.X / 2, panel9.Location.Y / 2, panel9.Width, panel9.Height);
g.DrawImage(bm, 0, 0);
}
代码有什么问题吗?
你必须设置PrintDocument.OriginAtMargins
财产要真实地考虑你的利润。
From MSDN http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.originatmargins(v=vs.110).aspx,
When OriginAtMargins is true, the Graphics object location takes into account the PageSettings.Margins property value and the printable area of the page
但从精确边缘进行打印取决于可打印区域,该区域由打印设备的物理限制定义。检查HardMarginX
and HardMarginY
获取打印机的物理来源。欲了解更多信息,请参阅答案this https://stackoverflow.com/questions/8761633/how-to-find-the-actual-printable-area-printdocument问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)