Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 802129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:33:10+00:00 2026-05-14T23:33:10+00:00

What am I missing I cant figure it out by the way this is

  • 0

What am I missing I cant figure it out by the way this is a simple tic tac toe game.

Also how can I incorporate a listbox with a horizontal scrollbar to select the player?

Player1 = (x) Or Player2 = (O)

Thanks in advance!!!

Main Form – xGameForm

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 MyGame
{
    public partial class xGameForm : Form
    {

        public Button xGameButton9;
        public Button xGameButton8;
        public Button xGameButton7;
        public Button xGameButton6;
        public Button xGameButton5;
        public Button xGameButton4;
        public Button xGameButton3;
        public Button xGameButton2;
        public Button xGameButton1;



        public Button[] _buttonArray;
        public bool isX;
        public bool isGameOver;

        Button tempButton = (Button)sender;

        public xGameForm()

        {
            InitializeComponent();
        }

        public void xGameForm_Load(object sender, EventArgs e)
        {
            _buttonArray = new Button[9] { xGameButton1, xGameButton2, xGameButton3, xGameButton4, xGameButton5, xGameButton6, xGameButton7, xGameButton8, xGameButton9 };

            for (int i = 0; i < 9; i++)

            this._buttonArray[i].Click += new System.EventHandler(this.ClickHandler);

            InitTicTacToe(); 

        }

        public void InitTicTacToe()
        {
            for (int i = 0; i < 9; i++)
            {
                _buttonArray[i].Text = "";
                _buttonArray[i].ForeColor = Color.Black;
                _buttonArray[i].BackColor = Color.LightGray;
                _buttonArray[i].Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            }
            this.isX = true;
            this.isGameOver = false;
        }

       public void ClickHandler(object sender, System.EventArgs e)
        {
            Button tempButton = (Button)sender;
            if( this.isGameOver )
            {
                MessageBox.Show("press reset to start a new game!","Game End",MessageBoxButtons.OK);
                return;         
            }
            if( tempButton.Text != "" ) 
            {
                return;
            }
            if( isX)    
                tempButton.Text = "X";
            else
                tempButton.Text = "O";
            isX = !isX; 
            this.isGameOver = Result1.CheckWinner(_buttonArray );
        }

       public void xGameResetButton_Click(object sender, EventArgs e)
        {
            InitTicTacToe();    
        }
}
    }

Class Result1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyGame
{
    public class Result1
    {


        static private int[,] Winners = new int[,]
                   {
                        {0,1,2},
                        {3,4,5},
                        {6,7,8},
                        {0,3,6},
                        {1,4,7},
                        {2,5,8},
                        {0,4,8},
                        {2,4,6}
                   };
        static public bool CheckWinner(Button[] myControls)
        {
            bool gameOver = false;
            for (int i = 0; i < 8; i++)
            {
                int a = Winners[i, 0], b = Winners[i, 1], c = Winners[i, 2];
                Button b1 = myControls[a], b2 = myControls[b], b3 = myControls[c];
                if (b1.Text == "" || b2.Text == "" || b3.Text == "")
                    continue;
                if (b1.Text == b2.Text && b2.Text == b3.Text)
                {
                    b1.BackColor = b2.BackColor = b3.BackColor = Color.LightCoral;
                    b1.Font = b2.Font = b3.Font = new System.Drawing.Font("Microsoft Sans Serif", 32F, System.Drawing.FontStyle.Italic & System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                    gameOver = true;
                    MessageBox.Show(b1.Text + " .... Wins the game!", "Game End", MessageBoxButtons.OK);
                    break;
                }
            }
            return gameOver;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:33:11+00:00Added an answer on May 14, 2026 at 11:33 pm

    Button is a class in the System.Windows.Forms namespace.
    Unless you import the namespace, the compiler won’t know which class you want.

    You need to import the namespace by adding using System.Windows.Forms; to the top of the class..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really missing something with anonymous types, because I can't figure out what
I must be missing something very simple, but can't find the answer to this.
This feels like a newbie issue, but I can't seem to figure it out.
I know this is pretty basic, but I can't figure it out. I've got
I've probably overlooked something simple, but I can't figure out how to convert a
There may be an easy way to do this but I can't see it...
I built a custom collector for Lucene.Net, but I can't figure out how to
I am trying to figure out the fastest way (in PHP 5) to check
I can't figure out how to encode a string + current hour in a
I am a new user of git and can't figure out how to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.