C# 毕业证书打印《二》

当证书的打印功能得以实现,最关键的功能便是数据。

通过对打印的了解,打印中最关键的功能便是打印事件中的方法。

 1  private void pd_PrintPage(object sender, PrintPageEventArgs ev)
 2         {
 3             //增加背景图,测试用
 4             //Graphics g = Graphics.FromImage(image);
 5             //ev.Graphics.DrawImage(image, 0, 0, image.Width, image.Height);
 6 
 7             for (int i = 0; i <= 15; i++)
 8             {
 9                 string drawString = op[i].Value;             
10                 Font drawFont = new Font(op[i].FontName, op[i].FontSize);
11                 SolidBrush drawBrush = new SolidBrush(Color.Black);    
12                 float x = op[i].X;
13                 float y = op[i].Y;
14                 // Set format of string.
15                 StringFormat drawFormat = new StringFormat();
16                 //drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
17                 // Draw string to screen.
18                 //ev.Graphics.PageUnit = GraphicsUnit.Millimeter;//将X、Y设置为cm格式
19                 ev.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
20             }
21         }
打印方法

在这里设置打印的字体、颜色、以及位置等信息。那么我们必须要一个类来保存该字段的信息。

所以我自定义了一个类OnePrint,用来存储要打印的字段信息

 1 public class OnePrintPoint
 2     {
 3         public string Key = "Lable";//关键字,控件的
 4         public float X = 0.0f;//x坐标
 5         public float Y = 0.0f;//y坐标
 6         public string FontName = "宋体";//字体名
 7         public float FontSize = 0.0f;//字体大小
 8         public string Value = "15";//
 9 
10         public OnePrintPoint()
11         { }
12         public OnePrintPoint(string key, float x, float y, string fontName, float fontSize, string value)
13         {
14             this.Key = key;
15             this.X = x;
16             this.Y = y;
17             this.FontName = fontName;
18             this.FontSize = fontSize;
19             this.Value = value;
20         }
21     }
自定义类

 

 接下来将是对打印机的设置,包括打印预览,打印。

 

未完待续……请继续关注!

 

posted @ 2013-06-17 10:07  FengLu-1  阅读(1388)  评论(0编辑  收藏  举报