c#打印文档
来源:互联网 发布:1848年革命 知乎 编辑:程序博客网 时间:2024/04/30 02:52
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsApplication3
- {
- public partial class Form1 : Form
- {
- string filename = "myfile.txt";
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- this.printDocument1.DocumentName = this.filename;
- this.printDocument1.Print();
- }
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- Graphics g = e.Graphics;
- using (Font font = new Font("Lucda Console", 72))
- {
- g.DrawString("hello,/nPrinter", font, Brushes.Black, 0, 0);
- }
- }
- }
- }