1.页面设置(PageSetupDialog)
pageSetupDialog1.Document = printDocument1; //必须设置打印对象,要不然不知道打印谁
pageSetupDialog1.ShowDialog(); //ShowDialog是打印这一栏里都有的方法
执行结果:
2.打印()
点击打印时执行代码:
private void button2_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
DialogResult dr= printDialog1.ShowDialog(); //判断点击的按钮是确定还是取消
if (dr == DialogResult.OK) //如果是确定就打印
{
printDocument1.Print();
}
}
打印对象PrintDocument触发事件
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Font f=new System.Drawing.Font("宋体",12); //造System.Drawing.Font 字体类型的对象
e.Graphics.DrawString(textBox1.Text,f,System.Drawing.Brushes.Aquamarine,10,10);
}
执行结果:
1.点击打印: 2.打印结果: