C# 证书打印《六》

时间:2022-06-07 15:00:26

整理思路,从新出发。

加载模版

 public void loadtemplate(Label lable)
{
string p_tempateFile = @"fomate.xml";
OnePrintPoint opp = new OnePrintPoint();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(p_tempateFile);
XmlElement xmlNodePoints = xmlDoc["Lable"];
XmlNodeList nodelist = xmlNodePoints.ChildNodes; foreach (XmlElement el in nodelist)//读元素值
{
try
{
string keystr = el.Attributes["Key"].InnerText;
if (keystr == lable.Name)
{
lable.Location = new Point(Convert.ToInt32(el.Attributes["X"].InnerText), Convert.ToInt32(el.Attributes["Y"].InnerText));
lable.Font = new Font(el.Attributes["FontName"].InnerText, float.Parse(el.Attributes["FontSize"].InnerText));
}
}
catch
{
MessageBox.Show("xml文件读取错误,请和管理员联系", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

加载模版

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

 /// <summary>
/// 设置打印值的属性
/// </summary>
/// <param name="key">xml文件中key的值</param>
/// <param name="value">表格中取到的值</param>
/// <returns></returns>
public OnePrintPoint SetValue(string key, string value)
{
// string p_tempateFile = @"..\..\bin\fomate.xml";
string p_tempateFile = @"fomate.xml";
OnePrintPoint opp = new OnePrintPoint();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(p_tempateFile);
XmlElement xmlNodePoints = xmlDoc["Lable"];
XmlNodeList nodelist = xmlNodePoints.ChildNodes; foreach (XmlElement el in nodelist)//读元素值
{
string keystr = el.Attributes["Key"].InnerText;
if (keystr == key)
{
//op.Key = el.Attributes["Key"].InnerText;
//设置打印值的属性
opp.FontName = el.Attributes["FontName"].InnerText;
opp.FontSize = float.Parse(el.Attributes["FontSize"].InnerText);
opp.X = float.Parse(el.Attributes["X"].InnerText);
opp.Y = float.Parse(el.Attributes["Y"].InnerText);
opp.Value = value;
break;
}
else
{ }
}
return opp;
}

赋值

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

                                                博客园bindot