c# 分页打印多行文本
来源:互联网 发布:妖姬葵 知乎 编辑:程序博客网 时间:2024/06/01 03:58
直接上代码了。
[code=csharp]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
text = this.textBox1.Text;
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.BeginPrint += new PrintEventHandler(pd_BeginPrint);
using (System.Windows.Forms.PrintPreviewDialog dlg = new PrintPreviewDialog())
{
dlg.Document = pd;
dlg.WindowState = FormWindowState.Maximized;
dlg.AllowTransparency = true;
dlg.AutoScaleMode = AutoScaleMode.Dpi;
dlg.ShowDialog();
}
}
void pd_BeginPrint(object sender, PrintEventArgs e)
{
sf = Size.Empty;
top = 0;
}
string text = string.Empty;
int top = 0;
Size sf = Size.Empty;
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
if (sf == Size.Empty)
{
sf =Size.Round ( e.Graphics.MeasureString(text, Font, e.MarginBounds.Width));
}
e.Graphics.SetClip(e.MarginBounds);
e.Graphics.DrawString(text, this.Font, Brushes.Black, new Rectangle(e.MarginBounds.Location.X,
e.MarginBounds.Location.Y + top * -1, sf.Width, sf.Height));
//e.Graphics.DrawString(text, this.Font, Brushes.Black, new PointF(0, top * -1));
if (top + e.MarginBounds.Height < sf.Height)
{
top = top + e.MarginBounds.Height;
e.HasMorePages = true;
}
}
}
}
[code=csharp]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
text = this.textBox1.Text;
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.BeginPrint += new PrintEventHandler(pd_BeginPrint);
using (System.Windows.Forms.PrintPreviewDialog dlg = new PrintPreviewDialog())
{
dlg.Document = pd;
dlg.WindowState = FormWindowState.Maximized;
dlg.AllowTransparency = true;
dlg.AutoScaleMode = AutoScaleMode.Dpi;
dlg.ShowDialog();
}
}
void pd_BeginPrint(object sender, PrintEventArgs e)
{
sf = Size.Empty;
top = 0;
}
string text = string.Empty;
int top = 0;
Size sf = Size.Empty;
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
if (sf == Size.Empty)
{
sf =Size.Round ( e.Graphics.MeasureString(text, Font, e.MarginBounds.Width));
}
e.Graphics.SetClip(e.MarginBounds);
e.Graphics.DrawString(text, this.Font, Brushes.Black, new Rectangle(e.MarginBounds.Location.X,
e.MarginBounds.Location.Y + top * -1, sf.Width, sf.Height));
//e.Graphics.DrawString(text, this.Font, Brushes.Black, new PointF(0, top * -1));
if (top + e.MarginBounds.Height < sf.Height)
{
top = top + e.MarginBounds.Height;
e.HasMorePages = true;
}
}
}
}
[/code]
没有测试上百页的,估计是有问题。
0 0
- c# 分页打印多行文本
- 打印多行文本
- C# Textbox 多行文本换行
- shell脚本打印多行文本到文件
- 多行文本绘制
- 多行文本框
- 多行文本绘制
- 多行文本溢出
- 多行文本溢出
- 控制多行文本
- 多行文本居中
- c# 如何取消多行文本框自动换行
- C# Label显示多行文本及换行(WinForm/WebForm)
- C# Label显示多行文本及换行(WinForm/WebForm)
- SetDlgItemText显示多行文本
- 多行文本弹出窗口
- ORACLE 多行文本合并
- libgdx 多行文本域
- 数据结构读书笔记
- matlab实现ICP(3D迭代最近点算法)
- UOJ 74 [UR #6]破解密码
- 数据库系统概论学习笔记(一):基本概念
- HDU - 2066 - 一个人的旅行
- c# 分页打印多行文本
- UVA 1515 Pool construction(最小割)
- 洛谷 1303——A*B Problem
- 一级路由器静态路由访问二级路由器的方法二
- 【PAT】1091. Acute Stroke
- Linux玩家的福音
- 回顾Activity的启动模式及其应用场景
- 500. Keyboard Row
- 软件架构的概念