My errors are:
Error 2 An object reference is required for the non-static field, method, or property 'home.Form9.Two TextBox(int, int)'
Error 1 An object reference is required for the non-static field, method, or property 'System.Windows .Forms.Control. Invoke(System.D elegate)'
Error 2 An object reference is required for the non-static field, method, or property 'home.Form9.Two TextBox(int, int)'
Error 1 An object reference is required for the non-static field, method, or property 'System.Windows .Forms.Control. Invoke(System.D elegate)'
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace home
{
public partial class Form9 : Form
{
public Form9()
{
InitializeComponent();
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
Thread th;
private void button1_Click(object sender, EventArgs e)
{
Invoke((MethodInvoker)delegate { test1(); });
Thread.Sleep(600);
}
string str;
string[] strArr;
private void test1()
{
TableLayoutPanel tlp = new TableLayoutPanel();
tlp.Name = "tlp";
tlp.AutoSize = true;
Label lb = new Label();
int count = 0;
str = textBox1.Text;
char[] splitchar = { ' ' };
strArr = str.Split(splitchar);
for (count = 0; count <= strArr.Length - 1; count++)
{
Label lbl = new Label();
lb.Name = "lab1" + count.ToString();
lbl.Width = 20;
lbl.Text = count.ToString();
tlp.Controls.Add(lbl, count, 0);
TextBox tb = new TextBox();
tb.Name = "txt" + count.ToString();
tb.BorderStyle = BorderStyle.FixedSingle;
tb.Width = 35;
//ar[i] = i;
//tb.Text = ar[i].ToString();
// tb.Text = textBox1.Text;
tb.Text = strArr[count];
tlp.Controls.Add(tb, count, 1);
Label lbb = new Label();
lbb.Name = "lab" + count.ToString();
lbb.Width = 20;
tlp.Controls.Add(lbb, count, 2);
flowLayoutPanel1.Controls.Add(tlp);
}
Sort(0, strArr.Length - 1);
}
public static void Sort( int left, int right)
{
if (left < right)
{
Invoke((MethodInvoker)delegate { TwoTextBox(left, right); });
int middle = (left + right) / 2;
Sort(left, middle);
//Sort(data, middle + 1, right);
//Merge(data, left, middle, middle + 1, right);
}
}
private
void TwoTextBox(int ac, int ac1)
{
string a = ac.ToString();
string b = ac1.ToString();
string[] ab = { a, b };
for (int i =ac; i <=ac1; i++)
{
Control[] controls = flowLayoutPanel1.Controls.Find("txt" + ab[i], true);
foreach (Control c in controls)
{
if (c is TextBox)
{
c.BackColor = System.Drawing.Color.Red;
}
}
}
}
}
}
Comment