如何将控件事件加载到xml文件并将其从xml加载到另一个表单? [英] how to load controls events to xml file and load that from xml to another form?
本文介绍了如何将控件事件加载到xml文件并将其从xml加载到另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在c#或vb
帮助请
我想在xml文件中提取并保存一些兴趣控制事件以从另一个表单调用....... ..
ex>
control- button =>事件 - 单击
in c# or vb
help please
I want to Extract and save some interest controls events in xml file to call from another form.........
ex>
control- button => event - click
推荐答案
//这是我从xml文件获取控件的代码,它工作正常,现在我想保存//控件事件(例如按钮)有事件点击)到xml文件并让他们到新的//控件。
使用System;
使用System.Drawing;
使用System .Linq;
使用System.Windows.Forms;
使用System.Xml.Linq;
名称空间WindowsFormsApplication_DynamicGUIFromXML
{
公共部分类Form1:表格
{
public Form1()
{
InitializeComponent();
XDocument guiConfig = XDocument.Load(@" ../../ Gui。 xml");
foreach(来自y in guiConfig.Descendants(" Item")中的XElement项目选择y)
{
控制tmp = new Control();
开关(item.Att ribute(type)。值)
{
case" Button":
tmp = new Button();
休息;
case" TextBox":
tmp = new TextBox();
break;
}
tmp.Name = item.Attribute(" name")。Value;
tmp.Text = item.Attribute(" text")。Value;
tmp.Location = new Point(Int32.Parse(item.Attribute(" x")。Value),Int32.Parse(item。属性(y)。值));
Controls.Add(tmp);
}
}
}
}
// *********** ************************************
// Gui的内容。 xml
// ************************* **********************
//<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>
//< Gui>
//< Item type =" Button"名称= QUOT; FOO"文本= QUOT;栏" X =" 100" Y =" 100" />
//< Item type =" TextBox"名称= QUOT; foo2的"文本= QUOT; BAR2" X =" 200" Y =" 200" />
//< / Gui>
//this my code for get controls from xml file it''s work good ,now I want save //controls Event (ex. button has event click) to xml file and get them to new //controls.
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Linq;
namespace WindowsFormsApplication_DynamicGUIFromXML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
XDocument guiConfig = XDocument.Load(@"../../Gui.xml");
foreach (XElement item in from y in guiConfig.Descendants("Item") select y)
{
Control tmp = new Control();
switch (item.Attribute("type").Value)
{
case "Button":
tmp = new Button();
break;
case "TextBox":
tmp = new TextBox();
break;
}
tmp.Name = item.Attribute("name").Value;
tmp.Text = item.Attribute("text").Value;
tmp.Location = new Point(Int32.Parse(item.Attribute("x").Value), Int32.Parse(item.Attribute("y").Value));
Controls.Add(tmp);
}
}
}
}
// ***********************************************
// Contents of Gui.xml
// ***********************************************
//<?xml version="1.0" encoding="utf-8" ?>
//<Gui>
// <Item type="Button" name="foo" text="bar" x="100" y="100" />
// <Item type="TextBox" name="foo2" text="bar2" x="200" y="200" />
//</Gui>
这篇关于如何将控件事件加载到xml文件并将其从xml加载到另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文