//private FormatPrint() //{ //} //public FormatPrint(string p_tempateFile) //{ // loadPrintTemplate(p_tempateFile); //} /// <summary> /// 设置打印点的值 /// </summary> /// <param name="p_Key"></param> /// <param name="p_Value"></param> public void SetValue(string p_Key, string p_Value) { p_Key = p_Key.ToUpper(); if (m_PrintPoint_List.Contains(p_Key)) { OnePrintPoint tmpOnePrintPoint = (OnePrintPoint)m_PrintPoint_List[p_Key]; tmpOnePrintPoint.Value = p_Value; } else { throw new Exception("打印模版中不存在Key为" + p_Key + "的节点"); } }
/// <summary> /// 从打印模版文件中读取点阵数据,并保存到Hash表中 /// </summary> /// <param name="p_tempateFile"></param> public void loadPrintTemplate(string p_tempateFile) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(p_tempateFile); XmlElement xmlNodePoints = xmlDoc["Points"]; XmlNodeList nodelist = xmlNodePoints.ChildNodes; m_PrintPoint_List.Clear(); foreach (XmlElement el in nodelist)//读元素值 { OnePrintPoint op = new OnePrintPoint(); op.Key = el.Attributes["Key"].InnerText; op.FontName = el.Attributes["FontName"].InnerText; op.FontSize = float.Parse(el.Attributes["FontSize"].InnerText); op.X = float.Parse(el.Attributes["X"].InnerText); op.Y = float.Parse(el.Attributes["Y"].InnerText); m_PrintPoint_List.Add(op.Key.ToUpper(), op); } }
// The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { for (int i = 0; i < m_PrintPoint_List.Count; i++) { OnePrintPoint tmpOnePrintPoint = (OnePrintPoint)m_PrintPoint_List.GetByIndex(i); // Create string to draw. string drawString = tmpOnePrintPoint.Value; // Create font and brush. Font drawFont = new Font(tmpOnePrintPoint.FontName, tmpOnePrintPoint.FontSize); SolidBrush drawBrush = new SolidBrush(Color.Black); // Create point for upper-left corner of drawing. float x = tmpOnePrintPoint.X; float y = tmpOnePrintPoint.Y; // Set format of string. StringFormat drawFormat = new StringFormat(); //drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft; // Draw string to screen. ev.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat); } }