Dha*_*alR 3 .net c# printing winforms
我正在尝试打印一些string
s Graphicss.DrawString()
.我已设置边距printdocument
但不是从页面的原点开始.我已margins
到(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);
}
Run Code Online (Sandbox Code Playgroud)
代码有什么问题?
您必须将该PrintDocument.OriginAtMargins
属性设置为true才能考虑边距.
来自MSDN,
When OriginAtMargins is true, the Graphics object location takes into account the PageSettings.Margins property value and the printable area of the page
但是从精确边缘打印取决于可打印区域,该可打印区域由打印设备的物理限制来定义.检查HardMarginX
并HardMarginY
获取打印机的物理原点.有关更多信息,请参阅此问题的答案.
归档时间: |
|
查看次数: |
3257 次 |
最近记录: |