How I can save controls created in run time in Windows Forms

后端 未结 3 731
一整个雨季
一整个雨季 2020-12-12 03:30

here\'s my code

private void make_Book(int x, int y, string name)
{
    #region Creating Book

    // this code is initializing the book(button)
    Button b         


        
3条回答
  •  盖世英雄少女心
    2020-12-12 03:44

    This is a sample of how to save load xml.

    public static void Save(string x, string y, string name)
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\appName"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\appName");
            }
    
    
            XmlDocument xmlDocument = new XmlDocument();
    
            string xml = string.Format(@"", x, y, name);
    
            xmlDocument.LoadXml(xml);
    
            xmlDocument.Save(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\appName\\button.xml");
        }
    
        public static Dictionary Load()
        {
            string address = "";
    
            if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\appName\\button.xml"))
            {
                return new Dictionary(){{"x",""},{"y",""},{"name",""}};
            }
    
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\appName\\button.xml");
    
            XmlNode button = xmlDocument.GetElementsByTagName("button").Item(0);
    
            XmlNode nameNode = button.SelectSingleNode("name");
            XmlNode xNode = button.SelectSingleNode("x");
            XmlNode yNode = button.SelectSingleNode("y");
    
            return new Dictionary() { { "name", nameNode.InnerText }, { "x", xNode.InnerText }, { "y", yNode.InnerText } };
        }
    

提交回复
热议问题