以文本格式打印事件xml文件c#
问题描述:
我正在将数据保存到xml文件中。现在,我试图以文本格式打印保存在xml文件中的数据。我应该怎么做?以文本格式打印事件xml文件c#
这是我的打印代码。
private void button4_Click(object sender, EventArgs e)
{
System.Windows.Forms.PrintDialog dlg = new System.Windows.Forms.PrintDialog();
dlg.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
}
delegate DialogResult ShowPrintDialog();
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDialog dlg = new PrintDialog();
dlg.ShowDialog();
ShowPrintDialog spd = new ShowPrintDialog(dlg.ShowDialog);
this.BeginInvoke(spd);
}
这是我将代码保存到XML文件的代码。
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\\Users\\HDAdmin\\Document\\SliceEngine\\SliceEngine\\bin\\Debug\\saya.xml");
XmlElement contentElement = xmlDoc.CreateElement("Patient");
XmlElement levelEl = xmlDoc.CreateElement("LevelPriority");
XmlText xmlText = xmlDoc.CreateTextNode(berjaya[1]);
levelEl.AppendChild(xmlText);
contentElement.AppendChild(levelEl);
xmlDoc.DocumentElement.AppendChild(contentElement);
XmlElement nameEl = xmlDoc.CreateElement("Name");
nameEl.InnerText = berjaya[3];
contentElement.AppendChild(nameEl);
xmlDoc.DocumentElement.AppendChild(contentElement);
XmlElement idEl = xmlDoc.CreateElement("Id");
idEl.InnerText = berjaya[39];
contentElement.AppendChild(idEl);
xmlDoc.DocumentElement.AppendChild(contentElement);
XmlElement bpEl = xmlDoc.CreateElement("BloodPressure");
bpEl.InnerText = berjaya[5];
contentElement.AppendChild(bpEl);
xmlDoc.DocumentElement.AppendChild(contentElement);
我也用berjaya[39]
这样做分割数据,我认为拆分可以忽略不计。
答
如果您打算使用Windows Forms进行自定义打印,那么执行大部分工作的类是PrintDocument类。您需要创建此类的实例,并将PrintDialog的PrintDocument属性设置为新创建的实例。
打印可能很复杂。为XML文件创建自定义打印作业所需的步骤太复杂,无法在此处列出答案,但我至少可以指出您朝着正确的方向。我会在printing with Windows Forms这里看看这个页面。