没有合适的资源?快使用搜索试试~ 我知道了~
C#实现打印功能代码实现下载
5星 · 超过95%的资源 需积分: 9 47 下载量 103 浏览量
2009-08-09
11:11:14
上传
评论
收藏 7KB TXT 举报
温馨提示
试读
7页
C#实现打印功能代码实现下载~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
资源推荐
资源详情
资源评论
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;
using System.Collections;
using System.IO;
namespace PrintDocDemo
{
public partial class frmPrint : Form
{
string[] lines;//保存读入的源文件
public PrintDocument pd;//打印文档对象
Font printfont;//打印使用的字体
int curline;//缓冲区的当前行
public frmPrint()
{
InitializeComponent();
pd = new PrintDocument();//创建打印文档实例
//为打印文档PrintDocument事件绑定处理方法
pd.PrintPage += new PrintPageEventHandler(this.PrintEveryPage);
//创建打印使用的字体
printfont = new Font("宋体", 9.5f);
curline = 0;
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Collections;
using System.IO;
namespace PrintDocDemo
{
public partial class frmPrint : Form
{
string[] lines;//保存读入的源文件
public PrintDocument pd;//打印文档对象
Font printfont;//打印使用的字体
int curline;//缓冲区的当前行
public frmPrint()
{
InitializeComponent();
pd = new PrintDocument();//创建打印文档实例
//为打印文档PrintDocument事件绑定处理方法
pd.PrintPage += new PrintPageEventHandler(this.PrintEveryPage);
//创建打印使用的字体
printfont = new Font("宋体", 9.5f);
curline = 0;
}
//打印每一页
private void PrintEveryPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float fltLines = 0;//一页中的行数
float fltYPos = 0;//每行的Y坐标
int nCount = 0;//已打印行数
float fltLeftMargin = e.MarginBounds.Left;//获取打印的起始位置
float fltTopMargin = e.MarginBounds.Top;
//计算一页中的行数
fltLines = e.MarginBounds.Height / printfont.GetHeight (e.Graphics);
//打印一页
while (nCount < fltLines && (nCount + curline < lines.Length))
{
fltYPos = fltTopMargin + (nCount * printfont.GetHeight(e.Graphics));
e.Graphics.DrawString(lines[curline + nCount], printfont, Brushes.Black, fltLeftMargin, fltYPos);
nCount++;
}
curline += nCount;
//如果未到达文件末尾,则继续打印
if (curline < lines.Length)
e.HasMorePages = true;
else //否则停止打印
{
e.HasMorePages = false;
curline = 0;
}
}
private void PrintEveryPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float fltLines = 0;//一页中的行数
float fltYPos = 0;//每行的Y坐标
int nCount = 0;//已打印行数
float fltLeftMargin = e.MarginBounds.Left;//获取打印的起始位置
float fltTopMargin = e.MarginBounds.Top;
//计算一页中的行数
fltLines = e.MarginBounds.Height / printfont.GetHeight (e.Graphics);
//打印一页
while (nCount < fltLines && (nCount + curline < lines.Length))
{
fltYPos = fltTopMargin + (nCount * printfont.GetHeight(e.Graphics));
e.Graphics.DrawString(lines[curline + nCount], printfont, Brushes.Black, fltLeftMargin, fltYPos);
nCount++;
}
curline += nCount;
//如果未到达文件末尾,则继续打印
if (curline < lines.Length)
e.HasMorePages = true;
else //否则停止打印
{
e.HasMorePages = false;
curline = 0;
}
}
剩余6页未读,继续阅读
资源评论
- EDMI_Shijun2015-06-09帮助我解决问题了 太好了
Alion
- 粉丝: 58
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功