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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:55:17+00:00 2026-06-16T10:55:17+00:00

I am dynamically adding labels and textboxes in a form while the program is

  • 0

I am dynamically adding labels and textboxes in a form while the program is running. How can I insert these components in a scroll pane so that no matter how many labels and textboxes I add they will fit in the form?

I don’t know if I’m being clear.. but what I want is to be able to add as many components as I like and not in the limited size of the form.. is there any way to do this?

This is my code right now:

public void generateFormDynamically()
{
      textBoxes = new TextBox[noOfPlayers];

      int xLabel = 95;
      int yLabel = 215;

      int xTextBox = 205;
      int yTextBox = 215;

      for (int i = 0; i < noOfPlayers; i++)
      {
           Label label = new Label();
           label.Text = "Player " + (i + 1) + ":";

           if (i == 0) label.Location = new Point(xLabel, yLabel);
           else
           {
               yLabel += 55;
               label.Location = new Point(xLabel, yLabel);
           }

           label.AutoSize = true;
           label.BackColor = System.Drawing.Color.Transparent;
           label.Font = new System.Drawing.Font("Segoe UI Semibold", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
           label.Name = "label" + (i + 2);
           label.Size = new System.Drawing.Size(68, 20);
           label.TabIndex = 6;
           label.Visible = true;
           label.Show();
           this.Controls.Add(label);

           TextBox textBox = new TextBox();

           if (i == 0) textBox.Location = new Point(xTextBox, yTextBox);
           else
           {
                yTextBox += 55;
                textBox.Location = new Point(xTextBox, yTextBox);
           }

           textBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
           textBox.Name = "textBox" + (i + 1);
           textBox.Size = new System.Drawing.Size(245, 20);
           textBox.TabIndex = 1;
           textBox.Text = "Player" + (i + 1);
           textBox.Visible = true;
           textBox.Show();
           textBoxes[i] = textBox;
           this.Controls.Add(textBox);
     }
}

Thanks for your help 🙂

  • 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-16T10:55:18+00:00Added an answer on June 16, 2026 at 10:55 am

    As others said, you can not add it to fixed form, and then adjust form. eventually, form will be too big. BUT, you can do is:

    1) add a panel on the form, the panel size is fixed (or anchored/docked).
    2) set panel AutoScroll to true.
    3) then add label/textbox.

    so, if too many label/textbox added, the scrollbar will show up.

    but still, it is a good idea to set a limit for the # of dynamic control.

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

Sidebar

Related Questions

I am dynamically adding labels to a form and I would like to set
I am adding labels dynamically to a page, there are a few labels that
I have a form that has an array of dynamically created labels of varying
I'm having trouble adding components to a form dynamically. What I'm trying to do
Im adding dynamically textboxes to my form using jquery like this: $(document).ready(function(){ var i
I'm adding dynamically labels to hbox, and i need to remove all spaces between
I currently have a StackPanel, that I am dynamically adding controls to. (Presently other
In code I am dynamically adding controls (e.g. TextBox, ComboBox, Label, etc) that I
I'm dynamically adding rows into my TableLayoutPanel but I just can't configure there height.
I am adding ComboBoxes dynamically at runtime as shown below. The problem that I

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.