时间:2022-03-09 09:34:22 | 栏目:.NET代码 | 点击:次
主窗体代码如下:
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
string line = null;
//设置一页的行数=打印区域的高度除以字体高度.
float pageLine = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
//循环打印每一行
for (int count = 0; count < pageLine && ((line=sr.ReadLine())!=null); count++)
{
float singleLine=e.MarginBounds.Top+(count*printFont.GetHeight(e.Graphics));
e.Graphics.DrawString(line, printFont, Brushes.Black, e.MarginBounds.Left, singleLine);
}
//判断是否继续打印
if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
}