求助各位大神:C#打印文件换行问题

zhizhi1991 2013-04-08 11:39:14
int CurrentLine = 0;
int TotalLinesPerPage = 0;
int LineLength = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Brush b = Brushes.Black;
Font f = fontDialog1.Font;
TotalLinesPerPage = (int)(e.MarginBounds.Height / f.Height);

for (int i = 0; i < TotalLinesPerPage && CurrentLine < sf.Length; i++, CurrentLine++)
{
string s="";
LineLength = (int)e.Graphics.MeasureString(sf[CurrentLine], f).Width;//获取当前行的长度
for (int n = 0; n <= LineLength / e.MarginBounds.X; n++)
{
if (LineLength > e.MarginBounds.X)
{

s += sf[CurrentLine].Substring(n * e.MarginBounds.X, e.MarginBounds.X) + Environment.NewLine;//运行是这句报错:"索引和长度必须引用该字符串内的位置。\r\n参数名: length"
e.Graphics.DrawString(s, f, b, e.MarginBounds.X, e.MarginBounds.Y + i * f.Height);
CurrentLine++;
}//判断当前行长度是否超多内页宽度,若超出则另取一行

else
{
s += sf[CurrentLine].Substring(n * e.MarginBounds.X);

}

}


}

if (CurrentLine == sf.Length)
e.HasMorePages = false;
else
e.HasMorePages = true;
}
求解如何修改使程序实现打印文档自动换行。。。
...全文
49 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhizhi1991 2013-04-09
  • 打赏
  • 举报
回复
T^T求帮忙…

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧