VS2005打印学习记录。
protected void Button1_Click(object sender, EventArgs e)
{
PrintDocument MyPrintDoc = new PrintDocument();
MyPrintDoc.PrintPage+=new PrintPageEventHandler(MyPrintDoc_PrintPage);
MyPrintDoc.Print();
}
protected void MyPrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
String drawString = "Sample Text";
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
float x = 150.0F;
float y = 50.0F;
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
e.HasMorePages=false;
}
{
PrintDocument MyPrintDoc = new PrintDocument();
MyPrintDoc.PrintPage+=new PrintPageEventHandler(MyPrintDoc_PrintPage);
MyPrintDoc.Print();
}
protected void MyPrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
String drawString = "Sample Text";
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
float x = 150.0F;
float y = 50.0F;
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
e.HasMorePages=false;
}
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemdrawingprinting.asp更多内容请到微软官方网站。本来项目是想用GUI的方式自己画图来实现,不过后来感觉那样实现起来比较麻烦,所以转成了去研究水晶报表了,故把代码贴在这里,以后可以查看。
作者:Apollo
出处:http://apollo.cnblogs.com/
如果您觉得本文对您的学习有所帮助,可通过“微信”或“支付宝”打赏博主,或者点击页面右下角【好文要顶】支持博主。
![](https://images.cnblogs.com/cnblogs_com/panxiangfu/834853/o_719652973597724144.png)
![](https://images.cnblogs.com/cnblogs_com/panxiangfu/834853/o_327056369803578188.png)
![](https://images.cnblogs.com/cnblogs_com/panxiangfu/834853/o_719652973597724144.png)