我在一个form中放了panel,button两个控件,现在我想使用xml文件来保存整个文件,读取xml的时候还能把整个文件还原成panel,button两个控件,该如何写?

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;
    namespace xml
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {            XmlDocument xmldoc = new XmlDocument();
                //加入XML的声明段落
                XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                xmldoc.AppendChild(xmlnode);
                //加入一个根元素
                XmlElement root = xmldoc.CreateElement("", "root", "");
                xmldoc.AppendChild(root);
                XmlElement ej = xmldoc.CreateElement("name");
                XmlElement ej1 = xmldoc.CreateElement("xname");
                ej1.InnerText = "bb";
                XmlElement dj = xmldoc.CreateElement("sex");
                dj.InnerText = "男";
                ej.AppendChild(ej1);
                root.AppendChild(ej);
                root.AppendChild(dj);
                xmldoc.Save(@"d:\x.xml");
            }
        }
    }
      

  2.   

    类似word软件   可以保存一个里面有文字又有图片的文件,还可以加载显示出来
      

  3.   

    读取/写入 XML文件,楼主去看XMLDocument/XMLReader/XMLWriter就知道怎么写了至于保存Panel/Button,主要是看你想保存什么信息了,比如Button的大小,Text等,就可以像下面这么写:
    <Button>
        <Text>button</Text>
        <Width>100</Width>
        ..........
    </Button>
      

  4.   

    这种资料难找?
    XML 读取 几百万张网页,
    xml保存好控件的属性,读出来后new一个新的控件对象,赋上相应属性,最后再把控件加到容器里,不就行了。xml的节点层次,节点名称,属性名称等自己定。
      

  5.   

    把form里的每个控件当成xml里的一个节点,把所需的控件的属性再写到相应的节点里就行了。
      

  6.   

    建议LZ看一下WPF,界面元素就是保存在XML文件的
      

  7.   

    http://blog.csdn.net/csshan/article/details/2056711 可以看看我曾写的
      

  8.   

    UP,UP   我现在已经将一个button保存到xml中了,接下来改如何从xml文件读取出来并在界面上显示?