Q:

the output of the array in turn in panel to labels C#

I faced with the problem. I have a panel with 20 labels. The function generator() assign each label the number of the array. Each number scrolls from 1 to needed number. But the problem is that the number is assigned out of order. For example first number assign to 1 label and the next number to 10 label, the next to 2 and the next to 11 etc.
But I need to output the numbers in rtl or ltr order.
I dont know how to fix it. Help, please.

public void generator() // присваивание текстбоксам значений 
    {
        generatedArray = getUniqueRandomArray(1, 81, 20).ToArray();

       for (int i = 0; i < panel1.Controls.Count; i++)
        {
            for (int j = 1; j < generatedArray[i] + 1; j++)
            {
                panel1.Controls[i].Text = j.ToString();
                Thread.Sleep(50);
                panel1.Controls[i].Refresh();
            }
        }
    }

I would be grateful for help :)

A:

To accomplish this, you could use some controls of your own, so that you can better define their behaviour (and do it in batch).
A custom class which derives from Label:
List<MyLabel> MyLabels = new List<MyLabel>();

public class MyLabel : Label
{
   public MyLabel()
   {
      //Define some default properties
      this.TextAlign = ContentAlignment.MiddleCenter;
      this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.Font = new Font("Calibri", 9f, FontStyle.Regular);
      this.BackColor = Color.White;
      this.ForeColor = Color.Black;
      this.Size = new Size(50, 20);
   }
}

Insert an array of custom labels inside a panel (this could be a custom control too).
 int LeftMargin = 20;
 int TopMargin = 20;
 int NumberOfLabels = 20;
 int LabelsPerRow = 5;
 int LabelsDistance = 10;
 int _idx = 0;

for (int y = 0; y < (NumberOfLabels / LabelsPerRow); y++)
{
   for (int x = 0; x < LabelsPerRow; x++)
   {
      MyLabels.Add(new MyLabel() { Parent = this.panel1 });
      MyLabels[_idx].Location = new Point((LeftMargin + ((MyLabels[_idx].Width + LabelsDistance) * x)),
                                          (TopMargin + ((MyLabels[_idx].Height + LabelsDistance) * y)));
      _idx++;
   }
}

This is the result:

if you simply change these fields:
 int LeftMargin = 1;
 int TopMargin = 1;
 int NumberOfLabels = 20;
 int LabelsPerRow = 20;
 int LabelsDistance = 1;

you get this:

Then, call your generator() method to fill the UI:
generator();

public async void generator()
{
   generatedArray = getUniqueRandomArray(1, 81, 20).ToArray();
   for (int i = 0; i < MyLabels.Count; i++)
   {
      for (int j = 1; j < generatedArray[i] + 1; j++)
      {
         await Task.Run(async () => await Task.Delay(500));

         //Set the text property of the custom labels. The order will be respected
         MyLabels[i].Text = j.ToString();
      }
}

You could also set the labels text property through the Panel.Controls[] array.
this.panel1.Controls[i].Text = j.ToString();

The order would be respected as well, but if the parent form closes, it causes an ArgumentOutOfRange Exception.

