Reputation: 1067
I am saving my data into an xml file. now, I am trying to print out the data saved in an xml file in text format. how should I do?
This is my code in printing.
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);
}
This is my code for saving the data to an XML file.
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);
I also do splitting data by using berjaya[39]
so, I think the splitting can be ignored.
Upvotes: 0
Views: 1254
Reputation: 9847
If you're looking to do custom printing with Windows Forms, the class that does most of the work is the PrintDocument class. You'll need to create an instance of this class, and set the PrintDialog's PrintDocument property to the newly created instance.
Printing can be complicated. The steps required to create a custom print job for an XML file are too complex to list in an answer here, but I can at least point you in the right direction. I'd take a look at this page here on printing with Windows Forms.
Upvotes: 1