作者:aska | 来源:互联网 | 2023-08-28 11:36
效果示意:
操作步骤:
1、新建winform项目及创建窗体
2、拖取 打印 相关控件
PageSetupDialog 、 PrintDialog 、 PrintDocument 、PrintPreviewDialog
3、设置上述控件的Document属性为相应的PrintDocument
4、设置按钮等控件 及 添加相应按钮事件
5、示意代码如下
public partial class Form3 : Form
this.printDocument1.OriginAtMargins = true;
this.pageSetupDialog1.EnableMetric = true;
private void btnSetPrint_Click(object sender, EventArgs e)
this.pageSetupDialog1.ShowDialog();
private void btnPrePrint_Click(object sender, EventArgs e)
this.printPreviewDialog1.ShowDialog();
private void btnPrint_Click(object sender, EventArgs e)
if (this.printDialog1.ShowDialog() == DialogResult.OK)
this.printDocument1.Print();
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
Font font = new Font("宋体", 12);
Brush bru = Brushes.Blue;
for (int i &#61; 1; i <&#61; 5; i&#43;&#43;)
e.Graphics.DrawString("Hello world ", font, bru, i*20, i*20);