c# 用XML保存控件的位置、大小等信息,XML格式如下,求写XML文件的函数,要具体代码
2个回答
展开全部
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("Root"局陵塌);
doc.AppendChild(root);
for (int i = 0; i < this.Controls.Count; i++)
{
XmlElement control = doc.CreateElement(Controls[i].GetType().ToString());
for (int i1 = 0; i1 < Controls[i].Controls.Count; i1++)
{
XmlElement item = doc.CreateElement(Controls[i].Controls[i1].GetType().ToString());
item.SetAttribute("桐圆Width", Controls[i].Controls[i1].Width.ToString());
item.SetAttribute("汪雹Height", Controls[i].Controls[i1].Height.ToString());
item.SetAttribute("Margin", Controls[i].Controls[i1].Margin.All + "," + Controls[i].Controls[i1].Margin.Left + "," + Controls[i].Controls[i1].Margin.Right + "," + Controls[i].Controls[i1].Margin.Top + "," + Controls[i].Controls[i1].Margin.Bottom);
item.SetAttribute("IsEditable", "false");
control.AppendChild(item);
}
root.AppendChild(control);
}
doc.Save(Application.StartupPath + "\\xml1.xml");
XmlElement root = doc.CreateElement("Root"局陵塌);
doc.AppendChild(root);
for (int i = 0; i < this.Controls.Count; i++)
{
XmlElement control = doc.CreateElement(Controls[i].GetType().ToString());
for (int i1 = 0; i1 < Controls[i].Controls.Count; i1++)
{
XmlElement item = doc.CreateElement(Controls[i].Controls[i1].GetType().ToString());
item.SetAttribute("桐圆Width", Controls[i].Controls[i1].Width.ToString());
item.SetAttribute("汪雹Height", Controls[i].Controls[i1].Height.ToString());
item.SetAttribute("Margin", Controls[i].Controls[i1].Margin.All + "," + Controls[i].Controls[i1].Margin.Left + "," + Controls[i].Controls[i1].Margin.Right + "," + Controls[i].Controls[i1].Margin.Top + "," + Controls[i].Controls[i1].Margin.Bottom);
item.SetAttribute("IsEditable", "false");
control.AppendChild(item);
}
root.AppendChild(control);
}
doc.Save(Application.StartupPath + "\\xml1.xml");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-08-04
展开全部
100.私信我
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询