动态生成的控件如何保存 在winform开发中,在窗体上放置一个richtextBox控件,在richtextBox上动态生成一个或多个comboBox,并设置了内容,当关闭了窗体后,combobox如何保存 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要保存什么???不太明白你的意思。既然是动态生成的combobox,只有运行时才会可见阿 @lostowner() 我想重新打开窗体时,comboBox和他的内容依旧存在 把位置和内容写入个文件,再次启动的时候读这个文件把控件显示出来。有数据库,用数据库也行。ini和xml文件是不错的选择。 @wdy9927() 能不能提供一个demo或者一个小的示范程序 //读的时候就这样,写得时候把内容写成下面这种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);} 晕倒~ 自己随便找找就能找到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);} 请高手解释一下为什么是这个结果? csgl中使用OpenGL扩展库wgl 窗体间通信问题? 在C#中怎样使用HOOK函数 c#设计表单时候,我关闭了一下,然后居然不知道打开哪个文件来打开表单设计界面了? 巨简单的问题! 请问ADO.NET中有什么比较好的数据以页的方式读取方法 限制考试时间 C# 调用 Webservice,报错404 toolstrip上添加DateTimePicker控件的传值问题 ===请教一个小问题:怎么建个只读属性。有固定的几个值。。=== 还是哪个 字符的问题
我想重新打开窗体时,comboBox和他的内容依旧存在
能不能提供一个demo或者一个小的示范程序
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);
}
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);
}