Loading controls from xml file
-
hi all, i know hot to write to xml files, but i'm having trouble doing what i need to do and can;t find adequite info on this type of problem. Here's one xml file below:
<?xml version="1.0" encoding="utf-8"?>
<controls>
<Label Content="Double-click to edit." Location="258, 178" Size="101, 13" ForeColor="-1" />
<LinkLabel Content="Double-click to edit." Location="532, 133" Size="101, 13" LinkColor="-1" />
<LinkLabel Content="Double-click to edit." Location="424, 212" Size="101, 13" LinkColor="-1" />
<Label Content="Double-click to edit." Location="282, 89" Size="101, 13" ForeColor="-1" />
<Label Content="Double-click to edit." Location="528, 178" Size="101, 13" ForeColor="-1" />
<LinkLabel Content="Double-click to edit." Location="528, 133" Size="101, 13" LinkColor="-1" />
<LinkLabel Content="Double-click to edit." Location="528, 149" Size="101, 13" LinkColor="-1" />
<Label Content="Double-click to edit." Location="528, 164" Size="101, 13" ForeColor="-1" />
</controls>... And what I need to do once I've opened this file in my app is:
foreach(control in XmlFile)
{
// do something...
}Can somebody please help me out with this? I'd appreciate any help at all. Thank you Bael
-
hi all, i know hot to write to xml files, but i'm having trouble doing what i need to do and can;t find adequite info on this type of problem. Here's one xml file below:
<?xml version="1.0" encoding="utf-8"?>
<controls>
<Label Content="Double-click to edit." Location="258, 178" Size="101, 13" ForeColor="-1" />
<LinkLabel Content="Double-click to edit." Location="532, 133" Size="101, 13" LinkColor="-1" />
<LinkLabel Content="Double-click to edit." Location="424, 212" Size="101, 13" LinkColor="-1" />
<Label Content="Double-click to edit." Location="282, 89" Size="101, 13" ForeColor="-1" />
<Label Content="Double-click to edit." Location="528, 178" Size="101, 13" ForeColor="-1" />
<LinkLabel Content="Double-click to edit." Location="528, 133" Size="101, 13" LinkColor="-1" />
<LinkLabel Content="Double-click to edit." Location="528, 149" Size="101, 13" LinkColor="-1" />
<Label Content="Double-click to edit." Location="528, 164" Size="101, 13" ForeColor="-1" />
</controls>... And what I need to do once I've opened this file in my app is:
foreach(control in XmlFile)
{
// do something...
}Can somebody please help me out with this? I'd appreciate any help at all. Thank you Bael
Maybe something like this?
XDocument xdc = XDocument.Load("YourFileHere");
var controls = xdc.Elements("controls");
foreach (var item in controls)
{
if (item.Name == "Label")
{
lbl = new System.Windows.Forms.Label();
lbl.Text = item.Attribute("Content").Value
}
else if(item.Name == "LinkLable"){
//create a link lable
}
//and so on
}modified on Sunday, February 7, 2010 12:11 PM
-
Maybe something like this?
XDocument xdc = XDocument.Load("YourFileHere");
var controls = xdc.Elements("controls");
foreach (var item in controls)
{
if (item.Name == "Label")
{
lbl = new System.Windows.Forms.Label();
lbl.Text = item.Attribute("Content").Value
}
else if(item.Name == "LinkLable"){
//create a link lable
}
//and so on
}modified on Sunday, February 7, 2010 12:11 PM
Oops, sorry. I misread one of the statements in your answer. With the part where you wrote: lbl.Text = "Doubble click here..."; ... What I actually need is the value of the controls corresponding "Content" attribute. Because the text inside the Content attribute is not always going to be "Double click to edit...".
-
Oops, sorry. I misread one of the statements in your answer. With the part where you wrote: lbl.Text = "Doubble click here..."; ... What I actually need is the value of the controls corresponding "Content" attribute. Because the text inside the Content attribute is not always going to be "Double click to edit...".