Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want save all Controls Properties for windows form into xml file and load it from xml file to creat new windows form.......
help please ..
c# or vb.net
Posted
Comments
Fred Flams 5-Feb-13 4:07am    
Rather than saving the control's properties inside an XML file, why don't use a ressource file. This is easily done with Visual Studio and is more flexible than standard XML (think about saving an image content inside XML).

There's a few articles here on CodeProject that deals with persisting Forms' settings. Check out these few:
Easier .NET settings management[^]
Windows Forms User Settings in C#[^] (also provides a link to this useful FAQ[^], in case you want/need to locate the file or something like that)
Save and restore Form position and layout with this component[^]
Windows Forms - Creating and Persisting Custom User Settings in C#[^]
 
Share this answer
 
heres a small sample

C#
internal class WinControlXmlBuilder
    {        
        private System.Xml.XmlTextWriter xmlWriter;
        private const string id = "DetailID";
        
        public WinControlXmlBuilder(Control controlToBuild, string xmlFilePath)
        {
            using (this.xmlWriter = new System.Xml.XmlTextWriter(xmlFilePath, null))
            {                
                this.WriteStart("FormDetails");
                this.WriteControlDetail(id, "AccessibleDefaultActionDescription", controlToBuild.AccessibleDefaultActionDescription);
                this.WriteEnd();
            }
        }
        private void WriteStart(string id)
        {
            this.xmlWriter.WriteStartDocument();
            this.xmlWriter.WriteStartElement(id);
        }
        private void WriteEnd()
        {
            this.xmlWriter.WriteEndElement();
            this.xmlWriter.WriteEndElement();
            this.xmlWriter.WriteEndDocument();
        }
        private void WriteControlDetail(string idShouldbeConst, string name, string detail)
        {
            this.xmlWriter.WriteStartElement(idShouldbeConst);
            this.xmlWriter.WriteElementString(name, detail);
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900