Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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;

                    }

                }


            }

        }      
        

    }
}

object reference is required for the non-static field, method, or property plz help me.
Posted
Updated 28-Oct-11 22:04pm
v2
Comments
OriginalGriff 29-Oct-11 4:09am    
Where? Which line?
Yogesh Pednekar 29-Oct-11 5:08am    
where is the error ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900