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 8609033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:46:23+00:00 2026-06-12T03:46:23+00:00

Depending of XML file contents, in run time the program must create dynamically textbox

  • 0

Depending of XML file contents, in run time the program must create dynamically textbox and labels. I want to organize this controls as the following inside a groupbox:

[label1] [textbox1]  [label2] [texbox2] [label3] [textbox]
[label4] [textbox4]  [label5] [textbox5] [...]

and so.

But I don’t know how to compute the X and Y values. I have tried several solutions, but no luck. Below my current implemenation which put the label and textbox per line:

[label1] [texbox1]
[labe2] [texbox2] 

and so.

       //list the disiciplanas from XML file
            //into combobox control.
            for (int i = 0,
                label_X = 20, label_Y = 20,
                textbox_X = 74, textbox_Y = 20,
                len = materias[0].ChildNodes.Count,
                line = 0, tmp_pos = 20;

                i < len;

                i++,
                tab_index++,
                line++,
                tmp_pos += 20
                )
            {
                XmlNode materia = materias[0].ChildNodes[i];
                Point label_position, textbox_position;
                Label label = new Label();
                TextBox textbox = new TextBox();

#if DEBUG_
                if (line == 3)
                {
                    label_X = 200 + tmp_pos;
                    label_Y = 25 + tmp_pos;
                }
                else
                {
                    label_X += 10;
                }

                textbox_Y = label_Y;

#else
                label_Y += 20;
                textbox_Y = label_Y;
#endif

                label.Text = "foo";

                textbox.Size = new Size(48, 20);
                textbox.Name = String.Format("nota{0}", fo.Name);

                label_position = new Point();
                label_position.X = label_X;
                label_position.Y = label_Y;

                textbox_position = new Point();
                textbox_position.X = textbox_X;
                textbox_position.Y = textbox_Y;

                label.Location = label_position;
                textbox.Location = textbox_position;
                textbox.Left = 150;
                textbox.TabIndex = tab_index;

                notas_panel.Controls.Add(label);
                notas_panel.Controls.Add(textbox);
            }

I hope this is clear. Thanks in advance

  • 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-06-12T03:46:24+00:00Added an answer on June 12, 2026 at 3:46 am

    The easiest way is don’t calculate them.

    Create a panel and get rid of it’s border. Create the dynamic controls on the panel and set the panel to Dock Top, then call BringToFront() (or could be SendToBack() I can never remember which way round they are to help with docking at run time.) on the panel.

    When you create the next lot the controls all have the same positions but their parent panel is automatically placed underneath the earlier one.

    The result should look like this:
    enter image description here

     public partial class Form1 : Form
    {
        List<Int32> Children;
        public Form1()
        {
            InitializeComponent();
            Children = new List<int>();
            Children.AddRange(Enumerable.Range(0, 20));
            ShowChildren();
        }
    
        private void ShowChildren()
        {
            for (int i = 0; i < Children.Count; i += 3)
            {
                AddRow(i, Children);
            }
        }
    
        private void AddRow(int startIndex, List<Int32> Nodes)
        {
            int NodesOnThisRow = 3;
            if (Nodes.Count - startIndex < 3)
                NodesOnThisRow = Nodes.Count - startIndex;
            Panel newPanel = new Panel();
            newPanel.Height = 25;
            int x = 8;
            for (int i = 0; i < NodesOnThisRow; i++)
            {
                Label L = new Label();
                TextBox T = new TextBox();
                //You could dock these left so they just appear one after the other, or since there
                //is only 3 you could just hard code the 3 x values, or calc them
                L.Left = x;
                T.Left = x + 120;
                L.Text = Nodes[startIndex + i].ToString();
                T.Text = Nodes[startIndex + i].ToString();
                x += 250;
                newPanel.Controls.Add(L);
                newPanel.Controls.Add(T);
            }
            groupBox1.Controls.Add(newPanel);
            newPanel.Dock = DockStyle.Top;
            newPanel.BringToFront();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I want the xml to be created dynamically because depending on
I have an XML file whose contents I want to sort by document order
I am parsing data from this XML url The text input varies, depending on
I have an XML file that contains database settings that may change depending on
I am loading an xml file in jwplayer to play videos depending on which
1)I have an XML file with the structure that I don't want really change.
When I use XmlReader to parse an XML file, I get different results depending
I have a command line program to validate an XML against an XSD file.
i want to embed a xml file to a resource file in my project,whenever
I have an xml file with items. I want to output the list of

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.