12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsPrintDocument
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- e.Graphics.DrawString("蝶恋花", new Font("宋体", 15), Brushes.Black, 350, 80);
- e.Graphics.DrawLine(new Pen(Color.Black, (float)3.00), 100, 185, 720, 185);
- e.Graphics.DrawString("伫倚危楼风细细,望极春愁,黯黯生天际。", new Font("宋体", 12), Brushes.Black, 110, 195);
- e.Graphics.DrawString("草色烟光残照里,无言谁会凭阑意。", new Font("宋体", 12), Brushes.Black, 110, 220);
- e.Graphics.DrawString("拟把疏狂图一醉,对酒当歌,强乐还无味。", new Font("宋体", 12), Brushes.Black, 110, 245);
- e.Graphics.DrawString("衣带渐宽终不悔。为伊消得人憔悴。", new Font("宋体", 12), Brushes.Black, 110, 270);
- e.Graphics.DrawLine(new Pen(Color.Black, (float)3.00), 100, 300, 720, 300);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("是否要预览打印文档", "打印预览", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- //开启操作系统的防锯齿功能,使预览到的文档的图形或线条更加平滑和流畅
- this.printPreviewDialog1.UseAntiAlias = true;
- //设置要预览的文档
- this.printPreviewDialog1.Document = this.printDocument1;
- printPreviewDialog1.ShowDialog();
- }
- else
- {
- //调用Print方法直接打印文档
- this.printDocument1.Print();
- }
- }
- }
- }
|