日期:2014-05-17 浏览次数:21003 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//PrintDocument类是实现打印功能的核心,它封装了打印有关的属性、事件、和方法
PrintDocument printDocument = new PrintDocument();
void printDocument_BeginPrint(object sender, PrintEventArgs e)
{
//也可以把一些打印的参数放在此处设置
}
void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
//打印啥东东就在这写了
Graphics g = e.Graphics;
Brush b = new SolidBrush(Color.Black);
Font titleFont = new Font("幼圆", 10);
string title = "0123456789.-";
g.DrawString(title, titleFont, b, new PointF((e.PageBounds.Width - g.MeasureString(title, titleFont).Width) / 2, 20));
//e.Cancel//获取或设置是否取消打印
//e.HasMorePages //为true时,该函数执行完毕后还会重新执行一遍(可用于动态分页)
}
void printDocument_EndPrint(object sender, PrintEventArgs e)
{
//打印结束后相关操作
}