在winform开发中,在窗体上放置一个richtextBox控件,在richtextBox上动态生成一个或多个comboBox,并设置了内容,当关闭了窗体后,combobox如何保存

解决方案 »

  1.   

    你要保存什么???不太明白你的意思。既然是动态生成的combobox,只有运行时才会可见阿
      

  2.   

    @lostowner() 
    我想重新打开窗体时,comboBox和他的内容依旧存在
      

  3.   

    把位置和内容写入个文件,再次启动的时候读这个文件把控件显示出来。有数据库,用数据库也行。ini和xml文件是不错的选择。
      

  4.   

    @wdy9927() 
    能不能提供一个demo或者一个小的示范程序
      

  5.   

    //读的时候就这样,写得时候把内容写成下面这种xml格式。
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<?xml version='1.0' encoding='utf-8'?>" 
    +"<Test >" 
    +"<ComboBox name='Combo1' left='110' top='110' width='110' height='110' value='111,1111'/>" 
    +"<ComboBox name='Combo2' left='120' top='120' width='120' height='120' value='22,222'/>" 
    +"<ComboBox name='Combo3' left='130' top='130' width='130' height='130' value='33,333'/>" 
    +"<ComboBox name='Combo4' left='140' top='140' width='140' height='140' value='44,4444'/>" 
    +"</Test>");XmlNodeList nodeList;
    XmlNode root = doc.DocumentElement;
    nodeList = root.SelectNodes("/Test//ComboBox");foreach (XmlNode book in nodeList)
    {
    Console.WriteLine(book.Attributes["name"].Value);
    Console.WriteLine(book.Attributes["left"].Value);
    Console.WriteLine(book.Attributes["top"].Value);
    Console.WriteLine(book.Attributes["width"].Value);
    Console.WriteLine(book.Attributes["height"].Value);
    Console.WriteLine(book.Attributes["value"].Value);
    }
      

  6.   

    晕倒~ 自己随便找找就能找到xml的读写。
    using System.Xml;
    1: 创建一个文件名叫 ComboBox.xml
    <?xml version="1.0" encoding="utf-8"?>
    <Test>
    </Test>2: 写
    XmlDocument xmlDoc=new XmlDocument();XmlNode root;
    XmlElement xe1;
    try
    {
    xmlDoc.Load("ComboBox.xml");
    root=xmlDoc.SelectSingleNode("Test");
    xe1=xmlDoc.CreateElement("ComboBox");
    }
    catch (Exception exp)
    {
    MessageBox.Show(exp.Message);
    return;
    }xe1.SetAttribute("name","Combo5");
    xe1.SetAttribute("left","100");
    xe1.SetAttribute("top","100");
    xe1.SetAttribute("width","100");
    xe1.SetAttribute("height","100"); 
    xe1.SetAttribute("value","44,55,6,,7,8"); 
    root.AppendChild(xe1);
    xmlDoc.Save("ComboBox.xml"); 3 读
    XmlDocument doc = new XmlDocument();
    XmlNodeList nodeList;
    XmlNode root;
    try
    {
    doc.Load("ComboBox.xml");
    root = doc.DocumentElement;
    nodeList = root.SelectNodes("/Test//ComboBox");
    }
    catch (Exception exp)
    {
    MessageBox.Show(exp.Message);
    return;
    }foreach (XmlNode book in nodeList)
    {
    Console.WriteLine(book.Attributes["name"].Value);
    Console.WriteLine(book.Attributes["left"].Value);
    Console.WriteLine(book.Attributes["top"].Value);
    Console.WriteLine(book.Attributes["width"].Value);
    Console.WriteLine(book.Attributes["height"].Value);
    Console.WriteLine(book.Attributes["value"].Value);
    }