zoukankan      html  css  js  c++  java
  • 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     }
    自定义类

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

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

  • 相关阅读:
    IDE-Sublime【3】-配置Node.js开发环境
    Java-Android【2】-弹出对话框
    Node.js-中文分词【1】-node-segment
    Java-Android【1】-控制手机震动
    IDE-Sublime【2】-代码智能提示插件SublimeCodeIntel的安装
    Node.js-安装配置【1】-在Windows XP系统配置环境变量
    Node.js-部署【1】-防火墙端口的配置
    Node.js-npm【1】-常用命令
    Node.js-视图引擎【1】-Swig集成express的安装与配置
    NoSQL-Redis【2】-HDEL给我的一个惊喜
  • 原文地址:https://www.cnblogs.com/bindot/p/zsdy2.html
Copyright © 2011-2022 走看看