Click here to Skip to main content
11,721,289 members (87,502 online)
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 4: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 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 279
2 Mika Wendelius 170
3 F-ES Sitecore 150
4 cyycoish 70
0 Sergey Alexandrovich Kryukov 2,209
1 OriginalGriff 969
2 F-ES Sitecore 660
3 Maciej Los 609
4 Richard MacCutchan 560


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2015
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