locked
tic tac toe. noughts & crosses game RRS feed

  • Question

  • Hello, I am really stuck. I have created a new form on my tic tac toe game. It has a page where you can pick the difficulity (radio buttons) then you chose X or Y (buttons) however when I debug and try to pick one of each of these it does not go through to the actual game its like the buttons do not work. Below is my code (any help would be great! I am very new to C#)

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace NoughtsandCrosses
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
            }

            bool[,] X, O;
            string player;
            bool finished; // true when the game finish
            int difficulity;
            string ButtonsIndexs; //Indexs of remaining buttons
            int x, y; //coordinate of button
            Random rnd;



            private void resetVars()
            {
                ButtonsIndexs = "123456789";
                finished = false;
                rnd = new Random();
                O = new bool[3, 3];
                X = new bool[3, 3];
            }



            private void getCoordinates(int p, out int x, out int y)
            {//change the variables x and y to the correct coordinate
                switch (p)
                {
                    case 1: x = 0; y = 0; break;
                    case 2: x = 0; y = 1; break;
                    case 3: x = 0; y = 2; break;
                    case 4: x = 1; y = 0; break;
                    case 5: x = 1; y = 1; break;
                    case 6: x = 1; y = 2; break;
                    case 7: x = 2; y = 0; break;
                    case 8: x = 2; y = 1; break;
                    default: x = 2; y = 2; break;
                }
            }




            private bool clicked(int index)
            {//true if it was clicked, false if it's still clickable
                return (ButtonsIndexs.IndexOf(index.ToString()) == -1);
            }
            private bool clicked(int index, string p)
            {//checks if "p" is written on the button with index "index"
                int a, b;
                switch (index)
                {
                    case 1: a = 0; b = 0; break;
                    case 2: a = 0; b = 1; break;
                    case 3: a = 0; b = 2; break;
                    case 4: a = 1; b = 0; break;
                    case 5: a = 1; b = 1; break;
                    case 6: a = 1; b = 2; break;
                    case 7: a = 2; b = 0; break;
                    case 8: a = 2; b = 1; break;
                    default: a = 2; b = 2; break;
                }
                if (p == "X")
                    return (X[a, b]);
                return (O[a, b]);
            }



            private void Write_buttonIndex(int index, string toWrite)
            {//Writing 'toWrite' in a button by knowing its index p
                switch (index)
                {
                    case 1: Write(toWrite, button1); break;
                    case 2: Write(toWrite, button2); break;
                    case 3: Write(toWrite, button3); break;
                    case 4: Write(toWrite, button4); break;
                    case 5: Write(toWrite, button5); break;
                    case 6: Write(toWrite, button6); break;
                    case 7: Write(toWrite, button7); break;
                    case 8: Write(toWrite, button8); break;
                    default: Write(toWrite, button9); break;
                }
            }




            private bool check(int i, int k, string toCheck, string toWrite)
            {
                //k=1 for rows, k=3 for columns, k=5-i for diagonals
                string P = (toWrite == "X") ? "O" : "X";
                if ((clicked(i, toCheck) && clicked(i + k, toCheck) && !clicked(i + k + k)))
                {
                    getCoordinates(i + k + k, out x, out y);
                    Write_buttonIndex(i + k + k, toWrite);
                    return true;
                }
                if ((clicked(i, toCheck) && clicked(i + k + k, toCheck) && !clicked(i + k)))
                {
                    getCoordinates(i + k, out x, out y);
                    Write_buttonIndex(i + k, toWrite);
                    return true;
                }
                if ((clicked(i + k, toCheck) && clicked(i + k + k, toCheck) && !clicked(i)))
                {
                    getCoordinates(i, out x, out y);
                    Write_buttonIndex(i, toWrite);
                    return true;
                }
                return false;
            }





            private void Write(string p, Button targetButton)
            {
                if (p == "O")
                {
                    targetButton.ForeColor = Color.Red;
                    O[x, y] = true; //the place (x,y) is occupied by an 'O'
                }
                else
                {
                    targetButton.ForeColor = Color.Blue;
                    X[x, y] = true; //the place (x,y) is occupied by an 'X'
                }
                targetButton.Text = p; //Writing X or O

                //Removing the index of the clicked button from ButtonIndexs
                if (targetButton == button1)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('1'), 1);
                if (targetButton == button2)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('2'), 1);
                if (targetButton == button3)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('3'), 1);
                if (targetButton == button4)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('4'), 1);
                if (targetButton == button5)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('5'), 1);
                if (targetButton == button6)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('6'), 1);
                if (targetButton == button7)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('7'), 1);
                if (targetButton == button8)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('8'), 1);
                if (targetButton == button9)
                    ButtonsIndexs = ButtonsIndexs.Remove(ButtonsIndexs.IndexOf('9'), 1);
            }



            private void EasyPCWrite(string p)
            {
                // a Random button index (to chose a random free button)
                int index = int.Parse(ButtonsIndexs[rnd.Next(ButtonsIndexs.Length)].ToString());
                switch (index)
                {
                    case 1: x = y = 0; Write(p, button1); break;
                    case 2: x = 0; y = 1; Write(p, button2); break;
                    case 3: x = 0; y = 2; Write(p, button3); break;
                    case 4: x = 1; y = 0; Write(p, button4); break;
                    case 5: x = 1; y = 1; Write(p, button5); break;
                    case 6: x = 1; y = 2; Write(p, button6); break;
                    case 7: x = 2; y = 0; Write(p, button7); break;
                    case 8: x = 2; y = 1; Write(p, button8); break;
                    case 9: x = 2; y = 2; Write(p, button9); break;
                }
            }




            private void NormalPCWrite(string p)
            {
                {
                    string q = (p == "X") ? "O" : "X";
                    //check to win
                    if (!check(1, 1, p, p))
                        if (!check(4, 1, p, p))
                            if (!check(7, 1, p, p))
                                if (!check(1, 3, p, p))
                                    if (!check(2, 3, p, p))
                                        if (!check(3, 3, p, p))
                                            if (!check(1, 4, p, p))
                                                if (!check(3, 2, p, p))
                                                    if (!check(1, 1, q, p))
                                                        //defend
                                                        if (!check(4, 1, q, p))
                                                            if (!check(7, 1, q, p))
                                                                if (!check(1, 3, q, p))
                                                                    if (!check(2, 3, q, p))
                                                                        if (!check(3, 3, q, p))
                                                                            if (!check(1, 4, q, p))
                                                                                if (!check(3, 2, q, p))
                                                                                    //play randomly
                                                                                    EasyPCWrite(p);
                }

            }



            private bool Diagonals(bool[,] current)
            {
                return (
                    (current[0, 0] && current[1, 1] && current[2, 2])
                    ||
                    (current[0, 2] && current[1, 1] && current[2, 0])
                    );
            }




            private bool Row(int p, bool[,] current)
            {
                return (current[p, 0] && current[p, 1] && current[p, 2]);
            }






            private bool Column(int p, bool[,] current)
            {
                return (current[0, p] && current[1, p] && current[2, p]);
            }








            private bool CheckForWinOrDraw(bool[,] current)
            {
                if (Row(0, current) || Row(1, current) || Row(2, current) || Column(0, current) || Column(1, current) || Column(2, current) || Diagonals(current))
                {
                    //updating score
                    if (current == X)
                        xLabel.Text = (int.Parse(xLabel.Text) + 1).ToString();
                    else
                        oLabel.Text = (int.Parse(oLabel.Text) + 1).ToString();
                    //game finished
                    finished = true;
                    MessageBox.Show(string.Format("{0} Wins", (ButtonsIndexs.Length % 2 == 0) ? "X" : "O"));//showing result
                }
                else
                {
                    if (ButtonsIndexs == "")
                    {
                        //game finished
                        finished = true;
                        MessageBox.Show("Draw");
                    }

                }
                return finished;
            }




            private bool wasClickedBefore(Button button, out int x, out int y)
            {
                x = y = 0;
                switch (button.Name)
                {
                    case "button1": x = 0; y = 0; break;
                    case "button2": x = 0; y = 1; break;
                    case "button3": x = 0; y = 2; break;
                    case "button4": x = 1; y = 0; break;
                    case "button5": x = 1; y = 1; break;
                    case "button6": x = 1; y = 2; break;
                    case "button7": x = 2; y = 0; break;
                    case "button8": x = 2; y = 1; break;
                    case "button9": x = 2; y = 2; break;
                }
                return (X[x, y] || O[x, y]);
            }




            private void playAgianButton_Click(object sender, EventArgs e)
            {
                resetVars();
                button1.Text =
                button2.Text =
                button3.Text =
                button4.Text =
                button5.Text =
                button6.Text =
                button7.Text =
                button8.Text =
                button9.Text =
                "";
                if (player == "O") player = "X";
                else
                {
                    player = "O";
                    if (difficulity == 0)
                        EasyPCWrite("X");
                    else
                        NormalPCWrite("X");
                }

            }




            private void gameButtons_Click(object sender, EventArgs e)
            {
                if (!wasClickedBefore(sender as Button, out x, out y) && !finished)
                {
                    if (player == "O")
                    {
                        //The user turn
                        Write("O", sender as Button);
                        if (!CheckForWinOrDraw(O))
                        {
                            //PC turn
                            if (difficulity == 0)
                                EasyPCWrite("X");
                            else
                                NormalPCWrite("X");
                            CheckForWinOrDraw(X);
                        }
                    }
                    else
                    {
                        //The user turn
                        Write("X", sender as Button);
                        if (!CheckForWinOrDraw(X))
                        {
                            //PC turn
                            if (difficulity == 0)
                                EasyPCWrite("O");
                            else
                                NormalPCWrite("O");
                            CheckForWinOrDraw(O);
                        }
                    }
                }
            }







           









            private void EasyRB_Click(object sender, EventArgs e)
            {
                difficulity = 0; //Easy level
            }
            private void NormalRB_CheckedChanged(object sender, EventArgs e)
            {
                difficulity = 1; //Normal Level
            }


            private void back_Click(object sender, EventArgs e)
            {
                  if (difficulity == 0)
                   EasyRB.Checked = true;
                else
                   NormalRB.Checked = true;
                playAgainButton.PerformClick();
                xLabel.Text = oLabel.Text = "0";
                tableLayoutPanel1.Visible = false;
                this.Size = new Size(229, 300);
            }








            private void mainButtons(object sender, EventArgs e)
            {
                player = (sender as Button).Text; //user choice, X or O
                this.Size = new Size(382, 300); //changes form size
                tableLayoutPanel1.Visible = true;
                if (difficulity == 0)
                    if (player == "O")
                        EasyPCWrite("X");
                    else
                        return;
                else
                    if (player == "O")
                        NormalPCWrite("X");
            }








            private void backButton_Click(object sender, EventArgs e)
            {
                Form1 f1 = new Form1();
                this.Hide();
                f1.Show();
            }











            private void Form3_Load(object sender, EventArgs e)
            {
                difficulity = 0;
        resetVars();
            }

    Thursday, February 14, 2013 3:03 PM

Answers

  • You don't have to add the line that SUN DOWN siad to do.  He doesn't realize that you posted the deigner code. 

    1) First comment out of your code all the Click Event. 

    2) Then double click on each button.  VS will automatically add the click event and automatically add the function.

    3) Take the commented out click events code and put it into the new click event that VS automatically added.

    I think these are the buttons that need to be fixed

    playAgianButton
    gameButtons
    easyRB
    back
    backButton


    jdweng

    • Marked as answer by amyc92 Friday, February 15, 2013 9:02 AM
    Thursday, February 14, 2013 4:50 PM

All replies

  • this is my designer:

    namespace NoughtsandCrosses
    {
        partial class Form3
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            #region Windows Form Designer generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.XButton = new System.Windows.Forms.Button();
                this.OButton = new System.Windows.Forms.Button();
                this.backButton = new System.Windows.Forms.Button();
                this.label1 = new System.Windows.Forms.Label();
                this.label2 = new System.Windows.Forms.Label();
                this.EasyRB = new System.Windows.Forms.RadioButton();
                this.NormalRB = new System.Windows.Forms.RadioButton();
                this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
                this.oLabel = new System.Windows.Forms.Label();
                this.button9 = new System.Windows.Forms.Button();
                this.button8 = new System.Windows.Forms.Button();
                this.button7 = new System.Windows.Forms.Button();
                this.button6 = new System.Windows.Forms.Button();
                this.button5 = new System.Windows.Forms.Button();
                this.button4 = new System.Windows.Forms.Button();
                this.button3 = new System.Windows.Forms.Button();
                this.button2 = new System.Windows.Forms.Button();
                this.button1 = new System.Windows.Forms.Button();
                this.playAgainButton = new System.Windows.Forms.Button();
                this.button10 = new System.Windows.Forms.Button();
                this.xLabel = new System.Windows.Forms.Label();
                this.tableLayoutPanel1.SuspendLayout();
                this.SuspendLayout();
                //
                // XButton
                //
                this.XButton.Location = new System.Drawing.Point(26, 75);
                this.XButton.Name = "XButton";
                this.XButton.Size = new System.Drawing.Size(75, 23);
                this.XButton.TabIndex = 0;
                this.XButton.Text = "X";
                this.XButton.UseVisualStyleBackColor = true;
                //
                // OButton
                //
                this.OButton.Location = new System.Drawing.Point(26, 155);
                this.OButton.Name = "OButton";
                this.OButton.Size = new System.Drawing.Size(75, 23);
                this.OButton.TabIndex = 1;
                this.OButton.Text = "O";
                this.OButton.UseVisualStyleBackColor = true;
                //
                // backButton
                //
                this.backButton.Location = new System.Drawing.Point(197, 227);
                this.backButton.Name = "backButton";
                this.backButton.Size = new System.Drawing.Size(75, 23);
                this.backButton.TabIndex = 2;
                this.backButton.Text = "Back";
                this.backButton.UseVisualStyleBackColor = true;
                //
                // label1
                //
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(23, 35);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(44, 13);
                this.label1.TabIndex = 3;
                this.label1.Text = "Play as:";
                //
                // label2
                //
                this.label2.AutoSize = true;
                this.label2.Location = new System.Drawing.Point(194, 35);
                this.label2.Name = "label2";
                this.label2.Size = new System.Drawing.Size(49, 13);
                this.label2.TabIndex = 4;
                this.label2.Text = "Difficulity";
                //
                // EasyRB
                //
                this.EasyRB.AutoSize = true;
                this.EasyRB.Location = new System.Drawing.Point(187, 81);
                this.EasyRB.Name = "EasyRB";
                this.EasyRB.Size = new System.Drawing.Size(48, 17);
                this.EasyRB.TabIndex = 5;
                this.EasyRB.TabStop = true;
                this.EasyRB.Text = "Easy";
                this.EasyRB.UseVisualStyleBackColor = true;
                //
                // NormalRB
                //
                this.NormalRB.AutoSize = true;
                this.NormalRB.Location = new System.Drawing.Point(187, 161);
                this.NormalRB.Name = "NormalRB";
                this.NormalRB.Size = new System.Drawing.Size(58, 17);
                this.NormalRB.TabIndex = 6;
                this.NormalRB.TabStop = true;
                this.NormalRB.Text = "Normal";
                this.NormalRB.UseVisualStyleBackColor = true;
                //
                // tableLayoutPanel1
                //
                this.tableLayoutPanel1.ColumnCount = 4;
                this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
                this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
                this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
                this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
                this.tableLayoutPanel1.Controls.Add(this.oLabel, 3, 2);
                this.tableLayoutPanel1.Controls.Add(this.button9, 2, 3);
                this.tableLayoutPanel1.Controls.Add(this.button8, 1, 3);
                this.tableLayoutPanel1.Controls.Add(this.button7, 0, 3);
                this.tableLayoutPanel1.Controls.Add(this.button6, 2, 1);
                this.tableLayoutPanel1.Controls.Add(this.button5, 1, 1);
                this.tableLayoutPanel1.Controls.Add(this.button4, 0, 1);
                this.tableLayoutPanel1.Controls.Add(this.button3, 2, 0);
                this.tableLayoutPanel1.Controls.Add(this.button2, 1, 0);
                this.tableLayoutPanel1.Controls.Add(this.button1, 0, 0);
                this.tableLayoutPanel1.Controls.Add(this.playAgainButton, 3, 0);
                this.tableLayoutPanel1.Controls.Add(this.button10, 3, 3);
                this.tableLayoutPanel1.Controls.Add(this.xLabel, 3, 1);
                this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
                this.tableLayoutPanel1.Name = "tableLayoutPanel1";
                this.tableLayoutPanel1.RowCount = 4;
                this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33667F));
                this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66333F));
                this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.66333F));
                this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33667F));
                this.tableLayoutPanel1.Size = new System.Drawing.Size(284, 262);
                this.tableLayoutPanel1.TabIndex = 7;
                this.tableLayoutPanel1.Visible = false;
                //
                // oLabel
                //
                this.oLabel.AutoSize = true;
                this.oLabel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.oLabel.Font = new System.Drawing.Font("Tahoma", 24F);
                this.oLabel.ForeColor = System.Drawing.Color.Red;
                this.oLabel.Location = new System.Drawing.Point(216, 130);
                this.oLabel.Name = "oLabel";
                this.oLabel.Size = new System.Drawing.Size(65, 43);
                this.oLabel.TabIndex = 12;
                this.oLabel.Text = "0";
                this.oLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                //
                // button9
                //
                this.button9.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button9.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button9.Location = new System.Drawing.Point(145, 176);
                this.button9.Name = "button9";
                this.button9.Size = new System.Drawing.Size(65, 83);
                this.button9.TabIndex = 8;
                this.button9.UseVisualStyleBackColor = true;
                //
                // button8
                //
                this.button8.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button8.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button8.Location = new System.Drawing.Point(74, 176);
                this.button8.Name = "button8";
                this.button8.Size = new System.Drawing.Size(65, 83);
                this.button8.TabIndex = 7;
                this.button8.UseVisualStyleBackColor = true;
                //
                // button7
                //
                this.button7.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button7.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button7.Location = new System.Drawing.Point(3, 176);
                this.button7.Name = "button7";
                this.button7.Size = new System.Drawing.Size(65, 83);
                this.button7.TabIndex = 6;
                this.button7.UseVisualStyleBackColor = true;
                //
                // button6
                //
                this.button6.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button6.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button6.Location = new System.Drawing.Point(145, 90);
                this.button6.Name = "button6";
                this.tableLayoutPanel1.SetRowSpan(this.button6, 2);
                this.button6.Size = new System.Drawing.Size(65, 80);
                this.button6.TabIndex = 5;
                this.button6.UseVisualStyleBackColor = true;
                //
                // button5
                //
                this.button5.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button5.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button5.Location = new System.Drawing.Point(74, 90);
                this.button5.Name = "button5";
                this.tableLayoutPanel1.SetRowSpan(this.button5, 2);
                this.button5.Size = new System.Drawing.Size(65, 80);
                this.button5.TabIndex = 4;
                this.button5.UseVisualStyleBackColor = true;
                //
                // button4
                //
                this.button4.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button4.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button4.Location = new System.Drawing.Point(3, 90);
                this.button4.Name = "button4";
                this.tableLayoutPanel1.SetRowSpan(this.button4, 2);
                this.button4.Size = new System.Drawing.Size(65, 80);
                this.button4.TabIndex = 3;
                this.button4.UseVisualStyleBackColor = true;
                //
                // button3
                //
                this.button3.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button3.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button3.Location = new System.Drawing.Point(145, 3);
                this.button3.Name = "button3";
                this.button3.Size = new System.Drawing.Size(65, 81);
                this.button3.TabIndex = 2;
                this.button3.UseVisualStyleBackColor = true;
                //
                // button2
                //
                this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button2.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button2.Location = new System.Drawing.Point(74, 3);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(65, 81);
                this.button2.TabIndex = 1;
                this.button2.UseVisualStyleBackColor = true;
                //
                // button1
                //
                this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.button1.Font = new System.Drawing.Font("Tahoma", 36F);
                this.button1.Location = new System.Drawing.Point(3, 3);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(65, 81);
                this.button1.TabIndex = 0;
                this.button1.UseVisualStyleBackColor = true;
                //
                // playAgainButton
                //
                this.playAgainButton.Dock = System.Windows.Forms.DockStyle.Top;
                this.playAgainButton.Location = new System.Drawing.Point(216, 3);
                this.playAgainButton.Name = "playAgainButton";
                this.playAgainButton.Size = new System.Drawing.Size(65, 23);
                this.playAgainButton.TabIndex = 9;
                this.playAgainButton.Text = "Play Again";
                this.playAgainButton.UseVisualStyleBackColor = true;
                this.playAgainButton.Visible = false;
                //
                // button10
                //
                this.button10.Dock = System.Windows.Forms.DockStyle.Bottom;
                this.button10.Location = new System.Drawing.Point(216, 236);
                this.button10.Name = "button10";
                this.button10.Size = new System.Drawing.Size(65, 23);
                this.button10.TabIndex = 10;
                this.button10.Text = "Back";
                this.button10.UseVisualStyleBackColor = true;
                //
                // xLabel
                //
                this.xLabel.AutoSize = true;
                this.xLabel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.xLabel.Font = new System.Drawing.Font("Tahoma", 24F);
                this.xLabel.ForeColor = System.Drawing.Color.Blue;
                this.xLabel.Location = new System.Drawing.Point(216, 87);
                this.xLabel.Name = "xLabel";
                this.xLabel.Size = new System.Drawing.Size(65, 43);
                this.xLabel.TabIndex = 11;
                this.xLabel.Text = "0";
                this.xLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                //
                // Form3
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(284, 262);
                this.Controls.Add(this.tableLayoutPanel1);
                this.Controls.Add(this.NormalRB);
                this.Controls.Add(this.EasyRB);
                this.Controls.Add(this.label2);
                this.Controls.Add(this.label1);
                this.Controls.Add(this.backButton);
                this.Controls.Add(this.OButton);
                this.Controls.Add(this.XButton);
                this.Name = "Form3";
                this.Text = "Form3";
                this.tableLayoutPanel1.ResumeLayout(false);
                this.tableLayoutPanel1.PerformLayout();
                this.ResumeLayout(false);
                this.PerformLayout();

            }

            #endregion

            private System.Windows.Forms.Button XButton;
            private System.Windows.Forms.Button OButton;
            private System.Windows.Forms.Button backButton;
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.Label label2;
            private System.Windows.Forms.RadioButton EasyRB;
            private System.Windows.Forms.RadioButton NormalRB;
            private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
            private System.Windows.Forms.Label oLabel;
            private System.Windows.Forms.Button button9;
            private System.Windows.Forms.Button button8;
            private System.Windows.Forms.Button button7;
            private System.Windows.Forms.Button button6;
            private System.Windows.Forms.Button button5;
            private System.Windows.Forms.Button button4;
            private System.Windows.Forms.Button button3;
            private System.Windows.Forms.Button button2;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button playAgainButton;
            private System.Windows.Forms.Button button10;
            private System.Windows.Forms.Label xLabel;
        }
    }

    Thursday, February 14, 2013 3:04 PM
  • You are dynamically creating the button but you did not specify what happens when you click the button.

    Try setting the button.Click event to the desired method call:
    button.Click += new EventHandler(ButtonClickMethodName);

    Thursday, February 14, 2013 4:34 PM
  • You don't have to add the line that SUN DOWN siad to do.  He doesn't realize that you posted the deigner code. 

    1) First comment out of your code all the Click Event. 

    2) Then double click on each button.  VS will automatically add the click event and automatically add the function.

    3) Take the commented out click events code and put it into the new click event that VS automatically added.

    I think these are the buttons that need to be fixed

    playAgianButton
    gameButtons
    easyRB
    back
    backButton


    jdweng

    • Marked as answer by amyc92 Friday, February 15, 2013 9:02 AM
    Thursday, February 14, 2013 4:50 PM
  • thanks for catching that Joel, reading is fundamental and I missed that it was designer code.
    Thursday, February 14, 2013 7:11 PM