winform 打印预览
code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsTest { public partial class Form8 : Form { public Form8() { InitializeComponent(); 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) { //打印预览 //指定要打印的文档 //printPreviewDialog1.Document = printDocument1; 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 = 1; i <= 5; i++) { e.Graphics.DrawString(lbMsg.Text, font, bru, 0, i * 20); } } } }