c#打印文档

来源:互联网 发布:1848年革命 知乎 编辑:程序博客网 时间:2024/04/30 02:52
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace WindowsApplication3
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         string filename = "myfile.txt";
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void button1_Click(object sender, EventArgs e)
  18.         {
  19.             this.printDocument1.DocumentName = this.filename;
  20.             this.printDocument1.Print();
  21.         }
  22.         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  23.         {
  24.             Graphics g = e.Graphics;
  25.             using (Font font = new Font("Lucda Console", 72))
  26.             {
  27.                 g.DrawString("hello,/nPrinter", font, Brushes.Black, 0, 0);
  28.             }
  29.         }
  30.     }
  31. }
原创粉丝点击