PrintDocument 实践

简单使用,直接上代码

1.设置打印页大小 和页边距

this.printDocument1.DefaultPageSettings = new System.Drawing.Printing.PageSettings()
{
    PaperSize = new System.Drawing.Printing.PaperSize("", 100, 100),
    Margins = new System.Drawing.Printing.Margins(3, 3, 3, 3)
};

2.打印预览

PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = printDocument1;
ppd.ShowDialog();

3.Print_Page事件

public Form1()
{
    InitializeComponent();
    this.printDocument1.PrintPage += printDocument1_PrintPage;
}

void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    var g = e.Graphics;

    //e.HasMorePages = true;
    //e.HasMorePages = false;
}

 

原文地址:https://www.cnblogs.com/pengzhen/p/4360914.html