Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Comments
Sergey Alexandrovich Kryukov 4-Feb-13 10:43am    
What is "extract and event"? What is "load an event"? After all, what is "event", in your understanding?
Events are something very different, you need to understand how they work, first.
The question makes no sense at all.
Perhaps if you explain your ultimate purpose, you can get some advice, but only if you do.

—SA
bbirajdar 4-Feb-13 11:04am    
worst question I have ever seen on CP
mar_morsh 4-Feb-13 11:44am    
//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
// ***********************************************
//
//<gui>
// <item type="Button" name="foo" text="bar" x="100" y="100">
// <item type="TextBox" name="foo2" text="bar2" x="200" y="200">
//

1 solution

//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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900