2014/11/28

11/28 第十週 使用陣列產生隨機變數

11/28  第十週  使用陣列產生隨機變數

一開始,先宣告一4*4的二維陣列以及隨機變數函數
再來進入到表單,設定每個按鈕的位置以及長寬
最後利用變數函數將設定值定在0~16
再把所有設定的內容ADD進去

EX:
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 WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        Button[,] Button = new Button[4, 4];
        Random irand = new Random();
        int rd = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int x;
            int width, height;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    Button[i, j] = new Button();
                    Button[i, j].Location = new Point(i * 50, j * 50);
                    x = (i + 1) * (j + 1);
                    width = 50;
                    height = 50;
                    Button[i, j].Size = new Size(width, height);
                    Button[i, j].Text = x.ToString();
                    rd = irand.Next(0, 16);
                    Button[i, j].Text = Convert.ToString(rd);
                    this.Controls.Add(Button[i, j]);
                }

            }
        }
    }
}




2014/11/22

期中報告作業

期中報告作業

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.Diagnostics;

namespace WindowsFormsApplication14
{
    public partial class Form1 : Form
    {
        Operator operator1 = new Operator();

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue >= 96 && e.KeyValue <= 105)
            {
                operator1.choose(textBox1, (char)(e.KeyValue - 48));
            }
            else if (e.KeyValue >= 48 && e.KeyValue <= 57)
            {
                operator1.choose(textBox1, (char)e.KeyValue);
            }
            else
            {
                switch (e.KeyValue)
                {
                    case 107:
                        operator1.choose(textBox1, '+');
                        break;
                    case 109:
                        operator1.choose(textBox1, '-');
                        break;
                    case 106:
                        operator1.choose(textBox1, '*');
                        break;
                    case 111:
                        operator1.choose(textBox1, '/');
                        break;
                    case 8:
                        operator1.choose(textBox1, 'B');
                        break;
                    case 13:
                        operator1.choose(textBox1, '=');
                        break;
                    case 27:
                        operator1.choose(textBox1, 'C');
                        break;
                    case 110:
                        operator1.choose(textBox1, '.');
                        break;
                    case 46:
                        operator1.choose(textBox1, 'D');
                        break;
                    default:
                        Debug.Print("keycode = " + (e.KeyValue).ToString());
                        break;
                }
            }
        }

        private void button20_Click(object sender, EventArgs e)
        {
            char ch = ((Button)sender).Text[0];
            if (((Button)sender).Text == "CE")
                ch = 'D';
            else if (((Button)sender).Text == "sqrt")
                ch = '@'; 
            
            operator1.choose(textBox1, ch);
            button5.Focus();
        }
    }

    public class Operator
    {
        private double num = 0.0, ans = 0.0;
        private char preOp;
        private int opConter = 0;
        private bool preIsOperator = true;
        private bool preIskEquals = true;
        private bool preIsDot = false;

        private string Run(char ch)
        {
            switch (ch)
            {
                case '+':
                    ans = ans + num;
                    break;
                case '-':
                    ans = ans - num;
                    break;
                case '*':
                    ans = ans * num;
                    break;
                case '/':
                    ans = ans / num;
                    break;
            }

            opConter = 0;
            return ans.ToString();
        }

        public void choose(TextBox textBox1, char ch)
        {
            switch (ch)
            {
                case '+':
                case '-':
                case '*':
                case '/':
                    if (!preIsOperator)
                    {
                        if (preOp == '\0') preOp = ch;
                        if (opConter > 0)
                            textBox1.Text = Run(preOp);
                        opConter++;
                        preIsOperator = true;
                    }

                    preIskEquals = false;
                    preIsDot = false;
                    preOp = ch;
                    break;
                case '=':
                    textBox1.Text = Run(preOp);
                    preIskEquals = true;
                    preIsOperator = true;
                    preIsDot = false;
                    break;
                case '@':
                    if (preIskEquals)
                    {
                        ans = Math.Sqrt(ans);
                        textBox1.Text = ans.ToString();
                    }
                    else
                    {
                        num = Math.Sqrt(num);
                        textBox1.Text = num.ToString();
                    }

                    break;
                case 'D': // CE
                    textBox1.Text = "0";
                    num = double.Parse(textBox1.Text);
                    break;
                case 'B': // BackSpace
                    if (textBox1.Text[textBox1.Text.Length - 1] == '.') preIsDot = false;

                    if (textBox1.Text.Length > 1)
                        textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
                    else
                        textBox1.Text = "0";

                    num = double.Parse(textBox1.Text);
                    break;
                case 'C':
                    textBox1.Text = "0";
                    num = ans = 0.0;
                    preIskEquals = true;
                    preIsOperator = true;
                    preIsDot = false;
                    break;
                case '.':
                    if (!preIsDot)
                    {
                        textBox1.Text += ".";
                        preIsOperator = false;
                        preIsDot = true;
                    }

                    break;
                default:
                    if (preIsOperator) textBox1.Text = "";
                    textBox1.Text += ch.ToString();
                    
                    if (preIskEquals)
                    {
                        ans = double.Parse(textBox1.Text);
                        num = 0.0;
                    }
                    else
                        num = double.Parse(textBox1.Text);

                    preIsOperator = false;
                    break;
            }

            Debug.Print("ans = " + ans.ToString() + ", num = " + num.ToString() + ", preOp = " + preOp.ToString() + ", ch = '" + ch.ToString() + "'\r\n");
        }
    }
}




2014/11/14

11/14 第八週 九九乘法表(VB)&圈叉遊戲(C#)

11/14 第八週  九九乘法表(VB)&圈叉遊戲(C#)

九九乘法表

首先,99乘法表部分
同樣打開Excel,利用巨集部分編輯程式
為了以防工作單內容有東西
所以我們可輸入一程式碼將內容清空
再來,宣告變數S(行數),i(被乘數),j(乘數)
做兩階迴圈產生i*j的數值並傳到各行列,即完成99乘法表

EX:
Private Sub CommandButton1_Click()
Range("a1:h9").Clear
S = 1
For i = 1 To 9
For j = 1 To 9
result = i & "*" & j & " = " & i * j
Cells(j, S).Value = result
Next j
S = S + 1
Next i
End Sub


圈叉遊戲

EX:
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 WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        Button[,] Button = new Button[4, 4];
        int c = 0;
        int i, j, r;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (i = 1; i < 4; i++)
            {
                for (j = 1; j < 4; j++)
                {
                    Button[i, j] = new Button();
                    Button[i, j].Location = new Point(80 + i * 80, 80 + j * 80);
                    Button[i, j].Size = new Size(80, 80);
                    this.Controls.Add(Button[i, j]);
                    Button[i, j].Click += new EventHandler(Button1_Click);

                }
            }

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            Button Buttons= sender as Button;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);
              if (r == 0)
               {
                   Button[i, j].Text = "O".ToString();
               }
              else
               {
                   Button[i, j].Text = "X".ToString();
               }
                  
            
        }

    }
}

2014/11/7

11/7第七週 自製陣列

11/7第七週  自製陣列

這次程式全程將利用程式碼來建立物件,不依靠任何工具箱的功能

首先,進入表單程式的畫面
接者,在 public partial class Form1 : Form裡頭輸入下列程式碼
     //System.Windows.Forms.Button Button1;
        System.Windows.Forms.Button[] Buttons;
        int c = 0;

然後,在表單程式( private void Form1_Load(object sender, EventArgs e))裡輸入
             mybutton();
            //Button1 = new System.Windows.Forms.Button();
            //Button1.Location = new Point(100, 100);
            //Button1.Size = new Size(100, 100);
            //Button1.Text = "happy";
            //Button1.BackColor = Color.Red;
            //this.Controls.Add(Button1);

接者建立private void Button1_Click(object sender, System.EventArgs e)
在內部輸入
            Button btn = (Button)sender;
            MessageBox.Show(btn.Text);

再來,建立 private void mybutton()
在內部設計一迴圈形成按鈕的形式
以及建立size大小、text名稱、BackColor按鈕背景顏色、按鈕位置

如此一來即可單單利用程式來建立出9宮格

Ex:
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
    {
        //System.Windows.Forms.Button Button1;
        System.Windows.Forms.Button[] Buttons;
        int c = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            mybutton();
            //Button1 = new System.Windows.Forms.Button();
            //Button1.Location = new Point(100, 100);
            //Button1.Size = new Size(100, 100);
            //Button1.Text = "happy";
            //Button1.BackColor = Color.Red;
            //this.Controls.Add(Button1);
        }

        private void Button1_Click(object sender, System.EventArgs e)
        {
            Button btn = (Button)sender;
            MessageBox.Show(btn.Text);
        }
        private void mybutton()
        {
            //Button1 = new System.Windows.Forms.Button();
            //Button1.Location = new Point(100, 100);
            //Button1.Size = new Size(100, 100);
            //Button1.Text = "happy";
            //Button1.BackColor = Color.Red;
            //this.Controls.Add(Button1);
            Buttons = new System.Windows.Forms.Button[9];
            for (int i = 0; i < 9; ++i)
            {
                Buttons[i] = new Button();
                this.Controls.Add(Buttons[i]);
                Buttons[i].Size = new Size(80, 80);
                Buttons[i].Text = i.ToString();
                Buttons[i].BackColor = Color.SkyBlue;
                Buttons[i].Click += new System.EventHandler(this.Button1_Click);
                if (i <= 2)
                {
                    Buttons[i].Location = new System.Drawing.Point(100 + i * 80, 100);
                }
                else if (i > 2 && i <= 5)
                {
                    Buttons[i].Location = new System.Drawing.Point(100 + (i - 3) * 80, 180);
                }
                else if (i > 5 && i <= 9)
                {
                    Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 80, 260);
                }
            }
        }
    }
}




2014/10/31

10/31第六週 補充圈叉遊戲玩家輸贏判斷

10/31第六週  補充圈叉遊戲玩家輸贏判斷

首先,一樣利用工具箱建立9個button、1個textbox

然後在 public partial class Form1 : Form裏頭輸入 int c=0;

接者,在表單程式裡輸入button1.Text = "";
依此類推輸入另外8個

接下來和上次一樣在每個button內輸入相同宣告、條件來判斷玩家下的是O or X
但是這次不先輸入連線判斷,改用judge();來撰寫
註:judge()可隨意命名,最後宣告物件程式碼相同即可

在程式最後建立 private void judge()
輸入判斷輸贏的假設條件,即可完成程式

Ex:
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
    {
        int c = 0;

        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 = "";
        }

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

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

            judge();
        }

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

            judge();
        }

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

            judge();
        }

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

            judge();
        }

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

            judge();
        }

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

            judge();
        }

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

            judge();
        }

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

            judge();
        }

        private void judge()
        {
            if ((button1.Text == "O" && button2.Text == "O" && button3.Text == "O") ||
               (button4.Text == "O" && button5.Text == "O" && button6.Text == "O") ||
               (button7.Text == "O" && button8.Text == "O" && button9.Text == "O") ||
               (button1.Text == "O" && button4.Text == "O" && button7.Text == "O") ||
               (button2.Text == "O" && button5.Text == "O" && button8.Text == "O") ||
               (button3.Text == "O" && button6.Text == "O" && button9.Text == "O") ||
               (button1.Text == "O" && button5.Text == "O" && button9.Text == "O") ||
               (button3.Text == "O" && button5.Text == "O" && button7.Text == "O"))
                MessageBox.Show("O WIN!");
            else if ((button1.Text == "X" && button2.Text == "X" && button3.Text == "X") ||
                (button4.Text == "X" && button5.Text == "X" && button6.Text == "X") ||
                (button7.Text == "X" && button8.Text == "X" && button9.Text == "X") ||
                (button1.Text == "X" && button4.Text == "X" && button7.Text == "X") ||
                (button2.Text == "X" && button5.Text == "X" && button8.Text == "X") ||
                (button3.Text == "X" && button6.Text == "X" && button9.Text == "X") ||
                (button1.Text == "X" && button5.Text == "X" && button9.Text == "X") ||
                (button3.Text == "X" && button5.Text == "X" && button7.Text == "X"))
                MessageBox.Show("X WIN!!");
        }
    }
}









2014/10/24

10/24第五週 補充10/17之賽車比賽

10/24第五週  補充10/17之賽車比賽

首先,利用工具箱建立以下物件
2個label (作為點數用)、一個textbox(作為累積總步數)、4個button(1、4為骰子,2、3為車)

然後,先在宣告欄的位置輸入using System.Threading;

接者,在 public partial class Form1 : Form裏頭輸入 int total1 = 0, total2 = 0;

再來,進入button1的程式裡輸入骰子的宣告、假設條件、迴圈以及輸贏的判斷

同理,button4也仿照button1的程式碼,即完成賽車遊戲

Ex:
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int total1 = 0, total2 = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, d2, sum;
            Random ran = new Random();
            d1 = ran.Next(1, 7);
            d2 = ran.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            sum = d1 + d2;
            for (int i = 1; i <= sum; i++)
            {
                button2.Left = (i + total1) * 5;
                Thread.Sleep(100);
                Application.DoEvents();
            }
            total1 = total1 + sum;
            textBox1.Text = Convert.ToString(total1);

            if (button2.Left >=100)
                MessageBox.Show("甲車贏");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int d1, d2, sum;
            Random ran = new Random();
            d1 = ran.Next(1, 7);
            d2 = ran.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            sum = d1 + d2;
            for (int i = 1; i <= sum; i++)
            {
                button3.Left = (i + total2) * 5;
                Thread.Sleep(100);
                Application.DoEvents();
            }
            total2 = total2 + sum;
            textBox1.Text = Convert.ToString(total2);

            if (button3.Left >= 100)
                MessageBox.Show("乙車贏");
        }
    }
}





10/24第五週 圈叉遊戲

10/24第五週  圈叉遊戲

首先,利用工具箱的button功能建立9個按鈕以及建立一個label

然後在public partial class Form1 : Form裏頭輸入int c;

再來進入表單程式輸入 button1.Text = "";
依樣畫葫蘆地把另外8個也輸入進去

最後,在每個按鈕的程式裡宣告變數以及假設條件
即可完成圈叉遊戲

Ex:
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 c;

        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 = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button1.Text = "O";
            else
                button1.Text = "X";

            button1.Enabled = false;

            if(button1.Text==button2.Text&button2.Text==button3.Text&button1.Text==button3.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button1.Text == button4.Text & button4.Text == button7.Text & button1.Text == button7.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button1.Text == button5.Text & button5.Text == button9.Text & button1.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button2.Text = "O";
            else
                button2.Text = "X";

            button2.Enabled = false;

            if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button2.Text == button5.Text & button5.Text == button8.Text & button2.Text == button8.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button3.Text = "O";
            else
                button3.Text = "X";

            button3.Enabled = false;

            if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button3.Text == button6.Text & button6.Text == button9.Text & button3.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button3.Text == button5.Text & button5.Text == button7.Text & button3.Text == button7.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button4.Text = "O";
            else
                button4.Text = "X";

            button4.Enabled = false;

            if (button4.Text == button5.Text & button5.Text == button6.Text & button4.Text == button6.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button1.Text == button4.Text & button4.Text == button7.Text & button1.Text == button7.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button5.Text = "O";
            else
                button5.Text = "X";

            button5.Enabled = false;

            if (button4.Text == button5.Text & button5.Text == button6.Text & button4.Text == button6.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button2.Text == button5.Text & button5.Text == button8.Text & button2.Text == button8.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button1.Text == button5.Text & button5.Text == button9.Text & button1.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button3.Text == button5.Text & button5.Text == button7.Text & button3.Text == button7.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button6.Text = "O";
            else
                button6.Text = "X";

            button6.Enabled = false;

            if (button4.Text == button5.Text & button5.Text == button6.Text & button4.Text == button6.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button3.Text == button6.Text & button6.Text == button9.Text & button3.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button7.Text = "O";
            else
                button7.Text = "X";

            button7.Enabled = false;

            if (button7.Text == button8.Text & button8.Text == button9.Text & button7.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button1.Text == button4.Text & button4.Text == button7.Text & button1.Text == button7.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button3.Text == button5.Text & button5.Text == button7.Text & button3.Text == button7.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

        private void button8_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button8.Text = "O";
            else
                button8.Text = "X";

            button8.Enabled = false;

            if (button7.Text == button8.Text & button8.Text == button9.Text & button7.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button2.Text == button5.Text & button5.Text == button8.Text & button2.Text == button8.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

        private void button9_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            label1.Text = Convert.ToString(r);

            if (r == 1)
                button9.Text = "O";
            else
                button9.Text = "X";

            button9.Enabled = false;

            if (button7.Text == button8.Text & button8.Text == button9.Text & button7.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button3.Text == button6.Text & button6.Text == button9.Text & button3.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }
            else if (button1.Text == button5.Text & button5.Text == button9.Text & button1.Text == button9.Text)
            {
                if (r == 1)
                    MessageBox.Show("O is winner!!");
                else
                    MessageBox.Show("X is winner!!");
            }

        }

    }
}