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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:43:54+00:00 2026-05-25T13:43:54+00:00

I am trying to find multiple labels using a for loop, but I’m only

  • 0

I am trying to find multiple labels using a for loop, but I’m only finding the last label. Here is my code:

string input = textBox1.Text;
int n = Convert.ToInt32(input);
for (i = 1; i <= n; i++)
{
    label.Name = "label" + i;
    label.Location = new Point(100, 100 + i * 30);
    label.TabIndex = i;
    label.Visible = true;
    //label[i].Name=
    label.Text = "jjgggg";


    this.Controls.Add(label);
}

I want all labels between 1 to 5 if I input 5.

  • 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-25T13:43:55+00:00Added an answer on May 25, 2026 at 1:43 pm

    You’re repeatedly assigning to the properties of the same label. You need something like:

    string input = textBox1.Text;
    int n = Convert.ToInt32(input);
    for (i = 1; i <= n; i++)
    {
        Label label = new Label();
        label.Name = "label" + i;
        label.Location = new Point(100, 100 + i * 30);
        label.TabIndex = i;
        label.Visible = true;
        label.Text = "jjgggg";
    
        this.Controls.Add(label);
    }
    

    You might also want to consider using an object initializer:

    string input = textBox1.Text;
    int n = Convert.ToInt32(input);
    for (i = 1; i <= n; i++)
    {
        Label label = new Label
        {
            Name = "label" + i,
            Location = new Point(100, 100 + i * 30),
            TabIndex = i,
            Visible = true,
            Text = "jjgggg"
        };
    
        this.Controls.Add(label);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching all over trying to find simple code to add multiple markers
I'm trying to use the freeware Multiple Find And Replace 1.00 suggested in this
I'm trying to make a search feature that will search multiple columns to find
Trying to find an example that has css rollover using sprites & sliding door
I am trying to find the intersection values between multiple arrays. for example code1
I've been trying to find something that will let me run multiple commands on
I've been trying to find information on this, but due to the immaturity of
I've been trying to find a string in PHP that matches something like this:
I’ve been trying to find a way to extend SharePoint breadcrumbs across multiple site
Possible Duplicate: Sort multidimensional array by multiple keys I am trying to find some

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.