C# winform绘图图面打印功能

2021-04-30 18:29

阅读:473

 1.打印预览调用

Font txtFont = new Font("宋体", 12, FontStyle.Regular);//正文字体
newPrint = new Printer(printDataGridView, txtFont, pd, null);
pd.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);

if (printDataGridView.Rows.Count > 0)
{
bool hasMorePage=newPrint.Print(ev.Graphics);
ev.HasMorePages = hasMorePage;
}
else
{
MessageBox.Show("没有需要打印的数据");
}

2.打印预览调用

if (!flag)
{
Font txtFont = new Font("宋体", 12, FontStyle.Regular);//正文字体
newPrint = new Printer(printDataGridView, txtFont, pd, null);
pd.PrintPage -= new PrintPageEventHandler(printDocument_PrintPage);
pd.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
}
previewDialog.Document = pd;//指向要打印的对象
previewDialog.ShowDialog();//打印预览对话框显示出来

3.打印设置

private void printDialog_Click(object sender, EventArgs e)
{
pageSetupDialog.Document = pd;
pageSetupDialog.ShowDialog();
}

效果图:

技术分享

 


评论


亲,登录后才可以留言!