using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
namespace printApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e)
{
printDialog1.ShowDialog();
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
printDocument1.Print();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"打印出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void printPreviewToolStripMunuItem_Click(object sender, EventArgs e)
{
try
{
printPreviewDialog1.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void PrintDoucument1_Print(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics g = e.Graphics;
float linesPerPage = 0;
float yPosition = 0;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
string line = null;
StringReader linenReader = new StringReader(richTextBox1.Text);
Font PrintFont = this.richTextBox1.Font;
SolidBrush myBrush = new SolidBrush(Color.Black);
linesPerPage = e.MarginBounds.Height / PrintFont.GetHeight(g);
while (count < linesPerPage && ((line = linenReader.ReadLine()) != null))
{
yPosition=topMargin+(count*PrintFont.GetHeight(g));
g.DrawString(line,PrintFont,myBrush,leftMargin,yPosition,new StringFormat());
count++;
}
if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
}
}
分享到:
相关推荐
VB.net实现打印的简单方法
vb.net 打印及打印预览源码示例
asp.net web打印控件asp.net web打印控件
asp.net简单实现web打印功能,效果还不错
ASP.NET标签打印源码 开发语言 : C# 数据库 : Access 开发工具 : VS2008 源码类型 : WinForm 注意:不带技术支持,有帮助文件,虚拟商品,发货不退,看好再拍。 一、源码描述 这是一款比较实用的打印源码,可以用于...
ASP.NET页面打印技术之打印清单\ASP.NET页面打印技术之打印清单
本DataGridView打印控件和.NET打印控件5.6版(含报表模板设计组件)2014年6月22日修改完成,完全免费,在.NET2.0及以上环境下都可以使用(VB打印、C#打印都是可以的),有帮助文档与使用实例。 与上一版本的5.5版...
.net条码打印软件源码2019
.net条码打印软件源码(包含多种条码打印)
很好的实现asp.net中报表的网络打印功能。
.Net中打印源码集合(打印方面汇总,.Net中打印源码集合)
.net 打印功能测试 vs 2008 .NET 打印控件的使用及程序代码的描述,
完善的.net报表打印程序,VB.net源码
.net条码打印软件源码.rar
关于ASP.NET页面打印技术的总结。讲解了包括IE直接打印、WebBrowser 控件技术、导出到Excel、Word中去打印等多项技术
实现了。net的打印功能 实现了 .net打印实现了 .net打印
在vb.net下实现的打印datagridview的类,在vb.net下实现的打印datagridview的类 源代码
VB.NET二维码生成和打印实例
.net 打印控件 我一直在用的,多看看吧,很好用的一个打印控件