Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB.NET
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 4-Feb-13 5:30am
Comments
Sergey Alexandrovich Kryukov at 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
aspnet_regiis -i at 4-Feb-13 11:04am
   
worst question I have ever seen on CP
mar_morsh at 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
// ***********************************************
//
//
//
//
//

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

//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>
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 200
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100