Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Windows Forms Layout using Xml

Windows Forms Layout using Xml

Scheduled Pinned Locked Moved XML / XSL
winformsxmlquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Devaang11
    wrote on last edited by
    #1

    Hi All, How can I control the layout of Windows forms using Xml file. Thank you, Devaang

    A 1 Reply Last reply
    0
    • D Devaang11

      Hi All, How can I control the layout of Windows forms using Xml file. Thank you, Devaang

      A Offline
      A Offline
      annathor
      wrote on last edited by
      #2

      I'am guessing you don't wanna use WPF. Use the classes in the System.xml namespace to parse the xml, and then dynamicly create and add controls to the form, setting the position, size, color, text and so on according to the data in the xml. (I am asuming you are using C#/.net). If you use c++/MFC you can do it with parsing the xml with a library like TinyXML and then create the controls dynamicly based on the data in the xml.

      D 1 Reply Last reply
      0
      • A annathor

        I'am guessing you don't wanna use WPF. Use the classes in the System.xml namespace to parse the xml, and then dynamicly create and add controls to the form, setting the position, size, color, text and so on according to the data in the xml. (I am asuming you are using C#/.net). If you use c++/MFC you can do it with parsing the xml with a library like TinyXML and then create the controls dynamicly based on the data in the xml.

        D Offline
        D Offline
        Devaang11
        wrote on last edited by
        #3

        Hi, yes I am using .Net/C# I need something like this. Suppose I have Xml like ; Now When I render "Windows Form" it has lable like in given xml. Thank you, Devaang

        A 1 Reply Last reply
        0
        • D Devaang11

          Hi, yes I am using .Net/C# I need something like this. Suppose I have Xml like ; Now When I render "Windows Form" it has lable like in given xml. Thank you, Devaang

          A Offline
          A Offline
          annathor
          wrote on last edited by
          #4

          well, lets asume you have created a class that contain the data parsed from the xml (lets call it LabelData) and that you have a list with objects of that type containing the data for all the lables you wants to add to the form (lets call the list LabelDataList). the code will look something like this.

          public class LabelData
          {
          public string Name;
          public string Text;
          public int x,y;
          public int width,height;
          ....
          // you should use get/set methodes insted of public variables
          };

          List LabelDataList;

          LabelDataList=new List();

          //parse the xml
          ....
          ....
          if (Node.NodeType == XmlNodeType.Element)
          {
          if (Node.Name == "Label")
          {
          XmlElement NodeElement = Node as XmlElement;
          LabelData tmpLD=new LabelData();
          //sett the variables in the tmpLD object to the values in the xml using the XmlElement methode GetAttribute
          LabelDataList.add(tmpLD);
          }
          }
          ....
          ....

          //loop through the parsed data
          foreach(LabelData ld in LabelDataList)
          {
          Label newLabel=new Label();
          newLabel.Name=ld.Name;
          newLabel.Text=ld.Text;
          newLabel.Location=new Point(ld.x, ld.y);
          newLabel.Size=new Size(ld.width, ld.height);
          ....
          ....
          this.Controls.Add(newLabel);
          }

          ofcourse you can create the labels and add them to the form directly in the loop you use to parse the xml too, when it comes to parsing the XML there is many ways to do it, maybe the easiest one is to load the data into a DataTable and loop through the rows in the DataTable.

          modified on Tuesday, August 11, 2009 4:11 AM

          D 1 Reply Last reply
          0
          • A annathor

            well, lets asume you have created a class that contain the data parsed from the xml (lets call it LabelData) and that you have a list with objects of that type containing the data for all the lables you wants to add to the form (lets call the list LabelDataList). the code will look something like this.

            public class LabelData
            {
            public string Name;
            public string Text;
            public int x,y;
            public int width,height;
            ....
            // you should use get/set methodes insted of public variables
            };

            List LabelDataList;

            LabelDataList=new List();

            //parse the xml
            ....
            ....
            if (Node.NodeType == XmlNodeType.Element)
            {
            if (Node.Name == "Label")
            {
            XmlElement NodeElement = Node as XmlElement;
            LabelData tmpLD=new LabelData();
            //sett the variables in the tmpLD object to the values in the xml using the XmlElement methode GetAttribute
            LabelDataList.add(tmpLD);
            }
            }
            ....
            ....

            //loop through the parsed data
            foreach(LabelData ld in LabelDataList)
            {
            Label newLabel=new Label();
            newLabel.Name=ld.Name;
            newLabel.Text=ld.Text;
            newLabel.Location=new Point(ld.x, ld.y);
            newLabel.Size=new Size(ld.width, ld.height);
            ....
            ....
            this.Controls.Add(newLabel);
            }

            ofcourse you can create the labels and add them to the form directly in the loop you use to parse the xml too, when it comes to parsing the XML there is many ways to do it, maybe the easiest one is to load the data into a DataTable and loop through the rows in the DataTable.

            modified on Tuesday, August 11, 2009 4:11 AM

            D Offline
            D Offline
            Devaang11
            wrote on last edited by
            #5

            Hi Annathor Thanks for your interest... As I have to generate class from xml right for it Fist I have to create schema from xml and then have to generate class from it. Can I use xml directly?? And second question is : I want to bind control from xml file. means suppose my xml like So it means "address" columns of database will be bind to textbox

            A 1 Reply Last reply
            0
            • D Devaang11

              Hi Annathor Thanks for your interest... As I have to generate class from xml right for it Fist I have to create schema from xml and then have to generate class from it. Can I use xml directly?? And second question is : I want to bind control from xml file. means suppose my xml like So it means "address" columns of database will be bind to textbox

              A Offline
              A Offline
              annathor
              wrote on last edited by
              #6

              English isn't my first language, so I don't understand your question. Do you want to store the column name in a text box? if so you could make a control that inherit from the textbox class like this: public class ExtendedTextbox:Textbox { public string ColumnName; } and use the ExtendedTextbox insted of the normal Textbox class. and save the column name in the ColumnName varible like this: ExtendedTextbox etb=new ExtendedTextbox (); etb.Name="Something"; etb.ColumnName="Something"; ... ... this.Controls.add(etb);

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups