2014年12月19日 星期五

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;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        int width, height;
        string a;
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[17];
     
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array

            button1.Text = "重新";

            for (int i = 0; i < 17; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    width = 50;
                    height = 50;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i,j].Text = (i*4+j).ToString();
                    this.Controls.Add(buttons[i, j]);
                    buttons[i,j].Click += new EventHandler(Button1_Click);
                }
            }

         
         
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            /*
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (buttons[i, j].Text == "0")
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }
            */
         
         
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    /*
                    if (sender == buttons[i, j])
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                    */
                    if (i < 3)
                    {
                        if (sender == buttons[i + 1, j])
                        {
                            a = buttons[i + 1, j].Text;
                            buttons[i + 1, j].Text = buttons[i, j].Text;
                            buttons[i, j].Text = a;
                            //i = i + 1;
                        }
                    }
                 
                    if (i > 0 )
                    {
                        if (sender == buttons[i - 1, j])
                        {
                            a = buttons[i - 1, j].Text;
                            buttons[i - 1, j].Text = buttons[i, j].Text;
                            buttons[i, j].Text = a;
                            //i = i - 1;
                        }
                    }
                    if (j < 3)
                    {
                        if (sender == buttons[i, j+1])
                        {
                            a = buttons[i, j+1].Text;
                            buttons[i , j+1].Text = buttons[i, j].Text;
                            buttons[i, j].Text = a;
                            //j = j + 1;
                        }
                    }
                    if (j > 0)
                    {
                        if (sender == buttons[i, j - 1])
                        {
                            a = buttons[i, j - 1].Text;
                            buttons[i, j - 1].Text = buttons[i, j].Text;
                            buttons[i, j].Text = a;
                           // j = j - 1;
                        }
                    }
                }


            }
         

         



        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 17);
            label1.Text = d1.ToString();


            for (int j = 1; j < 17; j++)
            {
                k = 16 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    width = 50;
                    height = 50;
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = array[i * 4 + j + 1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }






            //buttons[1, 1].Text = array[1].ToString();

            /*
            for (int j = 1; j < 10; j++)
            {
                //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
             */


            label2.Text = array[d1].ToString();

        }
    }
}

C# 陣列隨機亂數 messagebox

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;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        int width, height,x,a;
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[17];
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array



            for (int i = 0; i < 17; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    width = 50;
                    height = 50;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i,j].Text = (j*4+i).ToString();
                    this.Controls.Add(buttons[i, j]);
                    buttons[i,j].Click += new EventHandler(Button1_Click);
                }
            }

           
         
        }
        private void Button1_Click(object sender, EventArgs e)
        {
           
           
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (buttons[i, j].Text == "0")
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }
           
           
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (sender == buttons[i, j])
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 17);
            label1.Text = d1.ToString();


            for (int j = 1; j < 17; j++)
            {
                k = 16 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    width = 50;
                    height = 50;
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = array[i * 4 + j + 1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }






            //buttons[1, 1].Text = array[1].ToString();

            /*
            for (int j = 1; j < 10; j++)
            {
                //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
             */


            label2.Text = array[d1].ToString();

        }
    }
}

2014年12月12日 星期五

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;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int width, height,x;
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[17];

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {



            // Instantiating all the buttons in the array



            for (int i = 1; i < 17; i++)
            {
                array[i] = i;
            }



            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    width = 50;
                    height = 50;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i, j].Size = new Size(width, height);
                    x = array[(j - 1) * 4 + i - 1];
                    buttons[i, j].Text = array[x].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }


            /*
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i,j].Text = j.ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }

            */

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            int d1, tmp, i;

            Random irand = new Random(Guid.NewGuid().GetHashCode());
            d1 = irand.Next(1, 16);
            label1.Text = d1.ToString();


            for (int j = 1; j < 16; j++)
            {
                i = 15 - j + 1;
                tmp = array[d1];
                array[d1] = array[i];
                array[i] =tmp ;
            }

            buttons[1, 1].Text = array[1].ToString();


            for (int j = 1; j < 5; j++)
            {
                for (int a = 1; a < 5; a++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    width = 50;
                    height = 50;
                    x = array[(j - 1) * 4 + a - 1];
                    //buttons[j, a] = new Button();
                    buttons[j, a].Location = new Point(a * 50, j * 50);
                    buttons[j, a].Size = new Size(width, height);
                    x = array[(j - 1) * 4 + a - 1];
                    buttons[j, a].Text = array[x].ToString();
                    this.Controls.Add(buttons[j, a]);
                }


                label2.Text = array[d1].ToString();
            }
        }
    }
}

2014年12月5日 星期五

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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[9, 9];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int x;
            int width, height;
            int[] myarray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,};
            //陣列 0~15          
            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    Random rnd = new Random(Guid.NewGuid().GetHashCode());
                    //隨機產生亂數不重複
                    width = this.Size.Width;
                    height = this.Size.Height;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    //x = (i + 1) * (j + 1);
                    x = myarray[(j - 1) * 4 + i - 1];
                    width = 50;
                    height = 50;
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = x.ToString();
                    this.Controls.Add(buttons[i, j]);
                }

            }
        }
    }
}

2014年12月3日 星期三

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 WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        int c = 0;
        int r;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            button1.Text = "";
            button2.Text = "";
            button3.Text = "";
            button4.Text = "";
            button5.Text = "";
            button6.Text = "";
            button7.Text = "";
            button8.Text = "";
            button9.Text = "";
            //按鈕1~9字串是空白

        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button1.Text = "O";

            }
            else
            {
                button1.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button1.Enabled = false;
            if (button1.Text == button2.Text & button2.Text == button3.Text & button3.Text == button1.Text)
            {
                if(r==0)
                MessageBox.Show("O win");
                else
                    MessageBox.Show("X win");
            }
            if (button1.Text == button4.Text & button4.Text == button7.Text & button7.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button1.Text == button5.Text & button5.Text == button9.Text & button9.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if(r == 1)
                    MessageBox.Show("X win");
            }
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button2.Text = "O";
            }
            else
            {
                button2.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button2.Enabled = false;
            if (button1.Text == button2.Text & button2.Text == button3.Text & button3.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if(r == 1)
                    MessageBox.Show("X win");
            }
            if (button2.Text == button5.Text & button5.Text == button8.Text & button8.Text == button2.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button3.Text = "O";
            }
            else
            {
                button3.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button3.Enabled = false;
            if (button1.Text == button2.Text & button2.Text == button3.Text & button3.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button3.Text == button6.Text & button6.Text == button9.Text & button9.Text == button3.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button3.Text == button5.Text & button5.Text == button7.Text & button7.Text == button3.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button4.Text = "O";
            }
            else
            {
                button4.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button4.Enabled = false;
            if (button1.Text == button4.Text & button4.Text == button7.Text & button7.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button4.Text == button5.Text & button5.Text == button6.Text & button6.Text == button4.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button5.Text = "O";
            }
            else
            {
                button5.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button5.Enabled = false;
            if (button1.Text == button5.Text & button5.Text == button9.Text & button9.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button2.Text == button5.Text & button5.Text == button8.Text & button8.Text == button2.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button3.Text == button5.Text & button5.Text == button7.Text & button7.Text == button3.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button4.Text == button5.Text & button5.Text == button6.Text & button6.Text == button4.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button6.Text = "O";
            }
            else
            {
                button6.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button6.Enabled = false;
            if (button4.Text == button5.Text & button5.Text == button6.Text & button6.Text == button4.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button3.Text == button6.Text & button6.Text == button9.Text & button9.Text == button3.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
        }

        private void button7_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button7.Text = "O";
            }
            else
            {
                button7.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button7.Enabled = false;
            if (button1.Text == button4.Text & button4.Text == button7.Text & button7.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            
            if (button3.Text == button5.Text & button5.Text == button7.Text & button7.Text == button3.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button7.Text == button8.Text & button8.Text == button9.Text & button9.Text == button7.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }

        }

        private void button8_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button8.Text = "O";
            }
            else
            {
                button8.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button8.Enabled = false;
            if (button2.Text == button5.Text & button5.Text == button8.Text & button8.Text == button2.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button7.Text == button8.Text & button8.Text == button9.Text & button9.Text == button7.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }

        }

        private void button9_Click_1(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button9.Text = "O";
            }
            else
            {
                button9.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button9.Enabled = false;
            if (button1.Text == button5.Text & button5.Text == button9.Text & button9.Text == button1.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button3.Text == button6.Text & button6.Text == button9.Text & button9.Text == button3.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
            if (button7.Text == button8.Text & button8.Text == button9.Text & button9.Text == button7.Text)
            {
                if (r == 0)
                    MessageBox.Show("O win");
                else if (r == 1)
                    MessageBox.Show("X win");
            }
        }
    }

}

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 WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        int c = 0;
        int r;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            button1.Text = "";
            button2.Text = "";
            button3.Text = "";
            button4.Text = "";
            button5.Text = "";
            button6.Text = "";
            button7.Text = "";
            button8.Text = "";
            button9.Text = "";
           //修改button的名稱
        }

        private void button1_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button1.Text = "O";

            }
            else
            {
                button1.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button1.Enabled = false;
            judge();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button2.Text = "O";
            }
            else
            {
                button2.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button2.Enabled = false;
            judge();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button3.Text = "O";
            }
            else
            {
                button3.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button3.Enabled = false;
            judge();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button4.Text = "O";
            }
            else
            {
                button4.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button4.Enabled = false;
            judge();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button5.Text = "O";
            }
            else
            {
                button5.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button5.Enabled = false;
            judge();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button6.Text = "O";
            }
            else
            {
                button6.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button6.Enabled = false;
            judge();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button7.Text = "O";
            }
            else
            {
                button7.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button7.Enabled = false;
            judge();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button8.Text = "O";
            }
            else
            {
                button8.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button8.Enabled = false;
            judge();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            r = c % 2;
            c = c + 1;
            if (r == 0)
            {
                button9.Text = "O";
            }
            else
            {
                button9.Text = "X";
            }
            textBox1.Text = Convert.ToString(r);
            button9.Enabled = false;
            judge();
        }
        private void judge()
        {
            if ((button1.Text == "O" && button2.Text == "O" && button3.Text == "O") ||
             (button1.Text == "O" && button4.Text == "O" && button7.Text == "O") ||
             (button1.Text == "O" && button5.Text == "O" && button9.Text == "O") ||
             (button4.Text == "O" && button5.Text == "O" && button6.Text == "O") ||
             (button2.Text == "O" && button5.Text == "O" && button8.Text == "O") ||
             (button3.Text == "O" && button6.Text == "O" && button9.Text == "O") ||
             (button3.Text == "O" && button5.Text == "O" && button7.Text == "O") ||
             (button7.Text == "O" && button8.Text == "O" && button9.Text == "O"))
                MessageBox.Show("O Win");
            else if ((button1.Text == "X" && button2.Text == "X" && button3.Text == "X") ||
             (button1.Text == "X" && button4.Text == "X" && button7.Text == "X") ||
             (button1.Text == "X" && button5.Text == "X" && button9.Text == "X") ||
             (button4.Text == "X" && button5.Text == "X" && button6.Text == "X") ||
             (button2.Text == "X" && button5.Text == "X" && button8.Text == "X") ||
             (button3.Text == "X" && button6.Text == "X" && button9.Text == "X") ||
             (button3.Text == "X" && button5.Text == "X" && button7.Text == "X") ||
             (button7.Text == "X" && button8.Text == "X" && button9.Text == "X"))
                MessageBox.Show("X Win");

        }
    }
}