Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 584157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:52:06+00:00 2026-05-13T14:52:06+00:00

I have an Xml file. It’s format is as follows: ControlType > Content >

  • 0

I have an Xml file. It’s format is as follows:

ControlType > Content > LocationX > LocationY > ForeColor/LinkColor > Int > Int > Int > Int

File example:

<?xml version="1.0" encoding="utf-8"?>
<cs>
  <Label Content="Double-click to edit." LocationX="583" LocationY="254" A="255" R="255" G="255" B="255" />
  <LinkLabel Content="Double-click to edit." LocationX="613" LocationY="251" A="255" R="0" G="0" B="0" />
</cs>

Background: An Xml file is generated and saved on disk. When the user loads the Xml document into my application, my app will read the Xml file. And foreach control in the document, it will retrieve its properties, like so:

foreach(Control control in XmlFile)
{
     // get control type
     // get control content
     // get LocationX
     // get LocationY
     // get Color
     // get Int
     // get Int
     // get Int
     // get Int

     // Do something with retrieved data.
}

Here’s what I already have:

OpenFileDialog o = new OpenFileDialog();

o.Filter =
    "T Multimedia Format (*.mf)|*.mf|" +
    "Word Document (*.docx)|*.docx|" +
    "PDF Document (*.pdf)|*.pdf|" +
    "Text FIle (*.txt)|*.txt";
o.Title = "T 11 - Open Document";

using (o)
{
    if (o.ShowDialog() == DialogResult.OK)
    {
        XDocument xdc = XDocument.Load(o.FileName);

        var cs = xdc.Elements("cs");
        foreach (var im in cs)
        {
            if (im.Name == "Label")
            {
                Label label = new Label();
                label.MouseClick += new MouseEventHandler(label_MouseClick);
                label.MouseDown += new MouseEventHandler(label_MouseDown);
                label.MouseMove += new MouseEventHandler(label_MouseMove);
                label.MouseUp += new MouseEventHandler(label_MouseUp);
                label.MouseDoubleClick += new MouseEventHandler(label_MouseDoubleClick);

                label.Text = im.Attribute("Content").Value;

                label.Location = new Point(
                    Convert.ToInt32(im.Attribute("LocationX").Value),
                    Convert.ToInt32(im.Attribute("LocationY").Value));

                label.BackColor = Color.Transparent;
                label.ForeColor = Color.FromArgb(
                    Convert.ToInt32(im.Attribute("A").Value),
                    Convert.ToInt32(im.Attribute("R").Value),
                    Convert.ToInt32(im.Attribute("G").Value),
                    Convert.ToInt32(im.Attribute("B").Value));

                label.AutoSize = true;
                Canvas.Controls.Add(label);

                label.BringToFront();
            }
            else if (im.Name == "LinkLabel")
            {
                LinkLabel link = new LinkLabel();
                link.MouseClick += new MouseEventHandler(link_MouseClick);
                link.MouseDown += new MouseEventHandler(link_MouseDown);
                link.MouseMove += new MouseEventHandler(link_MouseMove);
                link.MouseUp += new MouseEventHandler(link_MouseUp);
                link.MouseDoubleClick += new MouseEventHandler(link_MouseDoubleClick);

                link.Text = im.Attribute("Content").Value;

                link.Location = new Point(
                    Convert.ToInt32(im.Attribute("LocationX").Value),
                    Convert.ToInt32(im.Attribute("LocationY").Value));

                link.BackColor = Color.Transparent;
                link.LinkColor = Color.FromArgb(
                    Convert.ToInt32(im.Attribute("A").Value),
                    Convert.ToInt32(im.Attribute("R").Value),
                    Convert.ToInt32(im.Attribute("G").Value),
                    Convert.ToInt32(im.Attribute("B").Value));

                link.AutoSize = true;
                Canvas.Controls.Add(link);

                link.BringToFront();
            }
        }
    }
}

… The above code generates zero errors. But, it just doesn’t work. No controls are being displayed on the form. Does anybody know why the above code won’t work, and how I can get it working?

All help is appreciated, thank you

Bael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:52:07+00:00Added an answer on May 13, 2026 at 2:52 pm

    I would suggest you a little more generic way:

    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (var controlTag in XDocument.Load("settings.xml").Root.Elements())
        {
            var controlType = Type.GetType(string.Format("System.Windows.Forms.{0}, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", controlTag.Name.LocalName), false);
            if (controlType == null || !typeof(Control).IsAssignableFrom(controlType))
            {
                continue;
            }
            var control = (Control)Activator.CreateInstance(controlType);
            control.Text = controlTag.Attribute("Content").Value;
            control.Location = new Point(
                int.Parse(controlTag.Attribute("LocationX").Value),
                int.Parse(controlTag.Attribute("LocationY").Value)
            );
            control.BackColor = Color.Transparent;
    
            control.MouseClick += mouseClick;
            control.MouseDown += mouseDown;
            control.MouseMove += mouseMove;
            control.MouseUp += mouseUp;
            control.MouseDoubleClick += mouseDoubleClick;
    
            Controls.Add(control);
        }
    
    }
    

    As for the color you could add an attribute to the xml file that will point to the property name of the control that we want to set and use reflection. For example:

    <?xml version="1.0" encoding="utf-8"?>
    <cs>
      <Label Content="Double-click to edit." LocationX="583" LocationY="254" A="255" R="255" G="255" B="255" ColorProperty="ForeColor" />
      <LinkLabel Content="Double-click to edit." LocationX="613" LocationY="251" A="255" R="0" G="0" B="0" ColorProperty="LinkColor" />
    </cs>
    

    By the way XAML already provides much of the functionality you are trying to achieve here. Of course it assumes WPF interface which might not be your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, we have xml file with this format: <A> <B> <C></C> <D></D> <D></D>
I have an XML file from which I am parsing some content to display
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have XML-file with settings like this <?xml version=1.0 encoding=utf-8 ?> <configuration> <configSections> <sectionGroup
We have XML file like below... <?xml version='1.0'?> <T0020 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd xmlns=http://www.safersys.org/namespaces/T0020V1> <IRP_ACCOUNT>
I have xml file like this <?xml version=1.0 encoding=UTF-8?> <specification xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=file://Desktop/normal.xsd> <university> <refstr>bdvl_te_skrm_stc</refstr>
i have xml file that looks like this: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE pointList SYSTEM
I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
Have an xml file <DataSource> <localdata> <add context=Localization> <parameter name=timeout type=int defaultvalue=60/> <parameter name=address
I have XML file which looks like this: <?xml version=1.0?> <results> <row id=100><name>name blah</name></row>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.