如何将winform的所有控件属性保存到xml文件中? [英] how to save all controls properties for winform into xml file?
本文介绍了如何将winform的所有控件属性保存到xml文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望将Windows窗体的所有控件属性保存到xml文件中,并将其从xml文件加载到创建新的窗口窗口.......
帮助请...
c#或vb.net
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
推荐答案
这里有一些关于CodeProject的文章处理持久化表单的设置。看看这几个:
更简单的.NET设置管理 [ ^ ]
C#中的Windows窗体用户设置 [ ^ ](还提供了链接到这个有用的常见问题解答 [ ^ ],以防您需要/需要找到文件或类似的东西)
保存并恢复表格位置和布局是组件 [ ^ ]
Windows窗体 - 在C#中创建和保留自定义用户设置 [ ^ ]
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#[^]
继承人小样本
heres a small sample
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);
}
}
这篇关于如何将winform的所有控件属性保存到xml文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文