C# 证书打印《六》

整理思路,从新出发。

加载模版

 1 public void loadtemplate(Label lable)
 2         {
 3             string p_tempateFile = @"fomate.xml";
 4             OnePrintPoint opp = new OnePrintPoint();
 5             XmlDocument xmlDoc = new XmlDocument();
 6             xmlDoc.Load(p_tempateFile);
 7             XmlElement xmlNodePoints = xmlDoc["Lable"];
 8             XmlNodeList nodelist = xmlNodePoints.ChildNodes;
 9 
10             foreach (XmlElement el in nodelist)//读元素值 
11             {
12                 try
13                 {
14                     string keystr = el.Attributes["Key"].InnerText;
15                     if (keystr == lable.Name)
16                     {
17                         lable.Location = new Point(Convert.ToInt32(el.Attributes["X"].InnerText), Convert.ToInt32(el.Attributes["Y"].InnerText));
18                         lable.Font = new Font(el.Attributes["FontName"].InnerText, float.Parse(el.Attributes["FontSize"].InnerText));
19                     }
20                 }
21                 catch 
22                 {
23                     MessageBox.Show("xml文件读取错误,请和管理员联系", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
24                 }
25             }
26         }
加载模版

 

在搞定鼠标对控件的控制后,下面接着就是读取数据,将数据和相应的控件对应起来。

 1 /// <summary>
 2         /// 设置打印值的属性
 3         /// </summary>
 4         /// <param name="key">xml文件中key的值</param>
 5         /// <param name="value">表格中取到的值</param>
 6         /// <returns></returns>
 7         public OnePrintPoint SetValue(string key, string value)
 8         {
 9             // string p_tempateFile = @"..\..\bin\fomate.xml";
10             string p_tempateFile = @"fomate.xml";
11             OnePrintPoint opp = new OnePrintPoint();
12             XmlDocument xmlDoc = new XmlDocument();
13             xmlDoc.Load(p_tempateFile);
14             XmlElement xmlNodePoints = xmlDoc["Lable"];
15             XmlNodeList nodelist = xmlNodePoints.ChildNodes;
16 
17             foreach (XmlElement el in nodelist)//读元素值 
18             {
19                 string keystr = el.Attributes["Key"].InnerText;
20                 if (keystr == key)
21                 {
22                     //op.Key = el.Attributes["Key"].InnerText;
23                     //设置打印值的属性
24                     opp.FontName = el.Attributes["FontName"].InnerText;
25                     opp.FontSize = float.Parse(el.Attributes["FontSize"].InnerText);
26                     opp.X = float.Parse(el.Attributes["X"].InnerText);
27                     opp.Y = float.Parse(el.Attributes["Y"].InnerText);
28                     opp.Value = value;
29                     break;
30                 }
31                 else
32                 {
33 
34                 }
35             }
36             return opp;
37         }
赋值

   到此为止,关于打印的基本功能就这样实现了,如果有什么问题,欢迎大家和我交流,欢迎转载!

                                                博客园bindot

posted @ 2013-07-16 16:19  FengLu-1  阅读(866)  评论(1编辑  收藏  举报