you can create XML file in
FormClosing
Event having node representing each control on the Form.
Represent each control as separate node inside the XML file.
eg
For combo-box you need to create combo-box node having all decedent node representing items of combo-box.
<combobox id="City">
<item id="one" selected="True">Mumbai</item>
<item id="two" selected="False">Gujarat</item>
</combobox>
During Form Load event read the XML and assign value of respective note to respective control.
Following is the code to Create XML file.
private static void Main()
{
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode productsNode = doc.CreateElement("products");
doc.AppendChild(productsNode);
XmlNode productNode = doc.CreateElement("product");
XmlAttribute productAttribute = doc.CreateAttribute("id");
productAttribute.Value = "01";
productNode.Attributes.Append(productAttribute);
productsNode.AppendChild(productNode);
XmlNode nameNode = doc.CreateElement("Name");
nameNode.AppendChild(doc.CreateTextNode("Java"));
productNode.AppendChild(nameNode);
XmlNode priceNode = doc.CreateElement("Price");
priceNode.AppendChild(doc.CreateTextNode("Free"));
productNode.AppendChild(priceNode);
doc.Save(@"Path");
}
Following is the result of above mention code.
="1.0"="UTF-8"<products>-<product id="01"><Name>Java</Name><Price>Free</Price></product></products>
You can use
XDocument
also. ie using
System.Xml.Linq;
Quick example
XDocument doc = new XDocument();
XElement docElement=new XElement("City");
doc.Add(docElement);
docElement.Add(new XElement("Thane"));
docElement.Add(new XElement("Pune"));
doc.Save(@"Path");