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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:26:10+00:00 2026-05-28T04:26:10+00:00

OK Here’s what I did and the values which were set vertical are copied

  • 0

OK Here’s what I did and the values which were set vertical are copied in the labels but horizontal. And only one column/row.

public partial class Form1 : Form
{
    private Label l;
    private Button bStart;
    private TextBox txtVnes;
    private Label[] pole;

    public Form1()
    {
        InitializeComponent();
        bStart = new Button();
        bStart.Location = new Point(240, 165);
        bStart.Width = 75;
        bStart.Height = 25;
        bStart.Text = "START";

        txtVnes = new TextBox();
        txtVnes.Location = new Point(240, 10);
        txtVnes.Width = 160;
        txtVnes.Height = 130;
        txtVnes.Multiline = true;

        int a = 0;
        pole = new Label[42];
        for (int i = 1; i <= 6; i++)
        {
            for (int j = 1; j <= 7; j++)
            {
                l = new Label();
                l.Name = "label" + i.ToString() + j.ToString();
                l.Text = "Z";
                l.Width = 20;
                l.Height = 20;
                l.TextAlign = ContentAlignment.MiddleCenter;
                l.Parent = this;
                l.BackColor = Color.FromArgb(100, 149, 237);
                l.Location = new Point(10 + (j - 1) * 25, 15 + (i - 1) * 25);
                pole[a] = l;
                this.Controls.Add(l);
                a++;

            }
        }

        this.Controls.Add(bStart);
        this.Controls.Add(txtVnes);

        bStart.Click += new EventHandler(bStart_Click);

    }


    private void bStart_Click(object sender, EventArgs e)
    {

        Regex regex = new Regex(@"^(\s)*(\d ){6}\d(\s)*$");
        bool isValid = true;
        string[] ts = txtVnes.Text.Split(new string[] { "\r\n" },
        StringSplitOptions.RemoveEmptyEntries);


        if (ts == null || ts.Length < 1 || ts.Length > 6)
        {
            MessageBox.Show("Not valid");
        }
        else
        {
            foreach (string t in ts)
            {
                if (regex.IsMatch(t) == false)
                {
                    MessageBox.Show("Not valid");
                    break;
                }
            }

        }

        if (isValid)
        {

            for (int i = 0; i < 6; i++)
            {
                if (i < ts.Length && regex.IsMatch(ts[i]))
                { 

                    pole[i].Text = ts[i];
                }
                else
                {
                    pole[i].Text = "not valid";
                }
            }

        }
    }

Here’s a photo

So here is the problem: When I click on the button bStart only one value is copied and replaced in one labe from the array of labels.
This should work like this: After the user clicks on the button bStart, all values from the textbox txtVnes should be copied in each label in the array of labels. All the labels have text “Z”, and after click on the button they should be changed with the values in the textbox txtVnes. As you can see i used l.Text = txtVnes.Text; to copy the values, but it doesn’t work. I appreciate if you can help me, thank you!

  • 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-28T04:26:11+00:00Added an answer on May 28, 2026 at 4:26 am

    You are always setting the text of the same label l. Since your labels are in the array pole, you should set the text to consecutive pole indices.

    I you want all the valid texts at the beginning:

    string[] ts = txtVnes.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
    int k = 0;
    for (int i = 0; i < ts.Length && k < 6; i++) {
        if (IsValid(ts[i])) { // Where IsValid is a method containing your validation logic.
            pole[k++].Text = ts[i];
        }
    }
    
    // Fill remaining labels
    for (int i = k; i < 6; i++) {
        pole[i].Text = "not valid";
    }
    

    Or, if you want vaild and invalid texts mixed:

    string[] ts = txtVnes.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
    for (int i = 0; i < 6; i++) {
        if (i < ts.Length && IsValid(ts[i])) { // Where IsValid is a method containing your validation logic.
            pole[i].Text = ts[i];
        } else {
            pole[i].Text = "not valid";
        }
    }
    

    Note that array indices begin at 0, not at 1.


    EDIT #2:

    The IsValid method would look like this:

    private static Regex regex = new Regex(@"^(\s)*(\d ){6}\d(\s)*$"); 
    
    private static bool IsValid(string s)
    {
        return regex.IsMatch(s);
    }
    

    To answer your question in the comment: Yes, my examples above have to be placed in bStart_Click.

    And there is also another error in your form constructor. this.Controls.Add(l); should be placed inside the inner for-loop, just after pole[a] = l;, otherwise only one label will be visible on your form.

    Finally after having implemented and anlyzed your code, I came to the conclusion that you want to be able to enter text in the following format into the textbox and then place the digits into corresponding labels:

    1 2 3 4 5 6 7
    2 3 4 6 7 8 0
    0 1 2 6 6 6 7
    1 2 3 4 5 6 7
    2 3 4 6 7 8 0
    0 1 2 6 6 6 7
    

    The complete code should look like this:

    public partial class Form1 : Form
    {
        private Button bStart;
        private TextBox txtVnes;
        private Label[] pole;
    
        public Form1()
        {
            InitializeComponent();
            bStart = new Button();
            bStart.Location = new Point(240, 165);
            bStart.Width = 75;
            bStart.Height = 25;
            bStart.Text = "START";
            bStart.Click += new EventHandler(bStart_Click);
            this.Controls.Add(bStart);
    
            txtVnes = new TextBox();
            txtVnes.Location = new Point(240, 10);
            txtVnes.Width = 160;
            txtVnes.Height = 130;
            txtVnes.Multiline = true;
            this.Controls.Add(txtVnes);
    
            int a = 0;
            pole = new Label[42];
            for (int i = 1; i <= 6; i++) {
                for (int j = 1; j <= 7; j++) {
                    var l = new Label();
                    l.Name = "label" + i.ToString() + j.ToString();
                    l.Text = "Z";
                    l.Width = 20;
                    l.Height = 20;
                    l.TextAlign = ContentAlignment.MiddleCenter;
                    l.Parent = this;
                    l.BackColor = Color.FromArgb(100, 149, 237);
                    l.Location = new Point(10 + (j - 1) * 25, 15 + (i - 1) * 25);
                    pole[a] = l;
                    this.Controls.Add(l);
                    a++;
                }
            }
        }
    
        private void bStart_Click(object sender, EventArgs e)
        {
            string[] ts = txtVnes.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int row = 0;
            for (int i = 0; i < ts.Length && row < 6; i++) {
                if (LineIsValid(ts[i])) {
                    for (int col = 0; col < 7; col++) {
                        pole[row * 7 + col].Text = ts[i][2 * col].ToString();
                    }
                    row++;
                }
            }
    
            // Fill remaining labels
            for (; row < 6; row++) {
                for (int col = 0; col < 7; col++) {
                    pole[row * 7 + col].Text = "Z";
                }
            }
        }
    
        private static Regex regex = new Regex(@"^(\s)*(\d ){6}\d(\s)*$");
    
        private static bool LineIsValid(string line)
        {
            return regex.IsMatch(line);
        }
    }
    

    Two nested loops are required in bStart_Click as well. One for the rows and one for the columns.

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

Sidebar

Related Questions

Here's my situation: I have a Data Template set up which contains a ToggleButton
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY
Here is the situation, I am attempting to fire a set of Gallio tests
Here is an example: I have a file 1.js, which has some functions. I
here is a debatable question which i want to achieve not sure how .
Here is the piece of code which I use to get the count from
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here a simple question : What do you think of code which use try
Here is my code, which takes two version identifiers in the form 1, 5,
Here is a part of my code which sends an email: servidor = smtplib.SMTP()

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.