int intPratn = 0;
//打印时的纵坐标
float fYposition = 0;
float fLeft = e.MarginBounds.Left;
float fTop = e.MarginBounds.Top;
string strfrmling = "";
while((intPratn<intpage)&&(strfrmling=MySreader.ReadLine())!=null)
{
fYposition = fTop + intPratn * frmFont.GetHeight(frmGraphics);
frmGraphics.DrawString(strfrmling,frmFont,new
SolidBrush(Color.Black),fLeft,fYposition,new StringFormat());
intPratn++;
}
if (strfrmling != null)
{
//没有打印完发出下一页打印事件
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}
继续添加菜单中其他命令:
private void 打印预览 PToolStripMenuItem_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
//打印预览内容
MySreader = new StringReader(myf.richTextBox1.Text);
try
{
//打印预览对话框
printPreviewDialog1.ShowDialog();
}
catch
{
printDocument1.PrintController.OnEndPrint(printDocument1,new
System.Drawing.Printing.PrintEventArgs());
}
}