打印程序的开发贡献给大家
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace print
{
public partial class Form1 : Form
{
private int CheckPoint;//定义全局变量表示为页面
public Form1()
{
InitializeComponent();
}
private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
MessageBox.Show(printDocument1.DocumentName + " 已经打印完成!"); //打印结束
}
private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
CheckPoint = 0; //打印开始
}
private void button1_Click(object sender, EventArgs e)
{
PageSetupDialog ps = new PageSetupDialog(); //通过模式窗体调用打印页面设置
ps.Document = printDocument1;
ps.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
PrintDialog pd = new PrintDialog(); //通过模式窗体调用打印
pd.Document = printDocument1;
if (pd.ShowDialog() != DialogResult.Cancel)
{
try
{
printDocument1.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
StringReader lineReader = new StringReader(zybRichTextBox1.Text);//注意引用IO,将我开发的自定义文本筐的内容读出来
try
{
PrintPreviewDialog ppd = new PrintPreviewDialog();//通过模式窗体调用打印页面设置
ppd.Document = printDocument1;
ppd.FormBorderStyle = FormBorderStyle.Fixed3D;
ppd.ShowDialog();
}
catch (Exception excep)
{
MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
CheckPoint = zybRichTextBox1.Print(CheckPoint, zybRichTextBox1.TextLength, e); //打印装载事件
if (CheckPoint < zybRichTextBox1.TextLength)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}
}
}
关于printDocument控件的更详细使用请查看微软官方网站MSDN
测试效果如图 C#.net 嘛!
呵呵,噶简单的程序。知道我们的系统怎么打印的吗?
专业的贸易类单证生成、打印、导出,专业的图文报表。
有兴趣在宁波从事程序员工作的朋友可以联系我,TEL:13967843603 QQ:540688290
宁波凯瑞计算机科技有限公司 www.carysoft.cn 原理一样把数据灌到datatable中,然后从datatable中获取,中间是复杂了点
页:
[1]