大侠帮忙看看
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev){
//表示可读取连续字符系列的读取器。
//实现从字符串进行读取的 TextReader。
TextReader tr = new StringReader(this.richTextBox1.Text);
//设置打印字体
Font printFont = this.richTextBox1.Font;
//每页的行数
float linesPerPage = 0;
//上边距加上行距
float yPos = 0;
int count = 0;
//左边缘坐标
float leftMargin = ev.MarginBounds.Left;
//上边缘坐标
float topMargin = ev.MarginBounds.Top;
string line = null;
SolidBrush myBrush = new SolidBrush(Color.Black);
//计算每页的行数
// MessageBox.Show("巨型高度为" + ev.MarginBounds.Height + " 字体行距为:"+printFont.GetHeight(ev.Graphics));
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
// MessageBox.Show("有"+linesPerPage.ToString()+"行");
// 逐行打印
while (count < linesPerPage && ((line = tr.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPos, new StringFormat());
count++;
// MessageBox.Show("读了" + count + "行");
}
// 还有没有打印内容则另打印一页
if (line!=null)
{
ev.HasMorePages = true;
}
else
{
ev.HasMorePages = false;
}
myBrush.Dispose();
}
这段程序打印只有一页的文件可以正常预览,超过两页就陷入死循环了,怎么回事啊 --------------------编程问答-------------------- 调试下,观察count,linesPerPage的值
补充:.NET技术 , C#