C# winform绘图图面打印功能
2021-04-30 18:29
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();
}
效果图:
上一篇:C# tostring() 方法
下一篇:Window 6大内置对象
文章标题:C# winform绘图图面打印功能
文章链接:http://soscw.com/index.php/essay/80516.html