DefaultPageSettings.Margins 不添加边距
DefaultPageSettings.Margins not adding margins
根据 documentation,添加这些代码应该会为打印文档添加边距,但是当我在我的代码中使用它时,我看不到添加任何边距。我对代码的使用是否正确?这是来自 MSDN 的代码:
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printer;
Margins margins = new Margins(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
这是我的代码:
printDoc = new PrintDocument();
PrinterSettings printSettings = new PrinterSettings();
PaperSize paperSize = new PaperSize("Receipt", 350, 700);
Margins margin = new Margins(2000, 1000, 2000, 1000);
printDoc.DefaultPageSettings.PaperSize = paperSize;
printDoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = printDoc;
DialogResult result = printPreview.ShowDialog();
printDoc.DefaultPageSettings.Margins = margin;
if (result == DialogResult.OK)
{
printDoc.Print();
}
之所以没有边距影响文档,是因为我没有把OriginAtMargins
的值改成true。所以你需要从 PrintDocument()
改变它,像这样:
New printDoc = new PrintDocument();
printDoc.OriginAtMargins = true; //Default is false
根据 documentation,添加这些代码应该会为打印文档添加边距,但是当我在我的代码中使用它时,我看不到添加任何边距。我对代码的使用是否正确?这是来自 MSDN 的代码:
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printer;
Margins margins = new Margins(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
这是我的代码:
printDoc = new PrintDocument();
PrinterSettings printSettings = new PrinterSettings();
PaperSize paperSize = new PaperSize("Receipt", 350, 700);
Margins margin = new Margins(2000, 1000, 2000, 1000);
printDoc.DefaultPageSettings.PaperSize = paperSize;
printDoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = printDoc;
DialogResult result = printPreview.ShowDialog();
printDoc.DefaultPageSettings.Margins = margin;
if (result == DialogResult.OK)
{
printDoc.Print();
}
之所以没有边距影响文档,是因为我没有把OriginAtMargins
的值改成true。所以你需要从 PrintDocument()
改变它,像这样:
New printDoc = new PrintDocument();
printDoc.OriginAtMargins = true; //Default is false