Tic tac toe in C++ onclick event example

So i'm using visual studio.NET to create a tic tac toe game in C++. What i have done so far, i created 9 lables i put them into an array. Now what I would like to do is do an onClick event change to X. I just cant seem to find an example of an onclick code in C++. Can any of you point me in the right direction.
Is it possible to show us the code.

I assume you are writing a GUI program.

Labels are usually what are called static labels (they have ID of IDC_STATIC normally) . They don't provide onClick events as they do not react to mouse clicks.

You would probably be better off changing them to BUTTON objects, but they are other alternative methods.
#pragma once


namespace tictactoe {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ label9;

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;

#pragma 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>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->label8 = (gcnew System::Windows::Forms::Label());
this->label9 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(106, 148);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"Exit";
this->button1->UseVisualStyleBackColor = true;
//
// button2
//
this->button2->Location = System::Drawing::Point(26, 147);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 1;
this->button2->Text = L"Reset";
this->button2->UseVisualStyleBackColor = true;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(41, 22);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(82, 22);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(35, 13);
this->label2->TabIndex = 3;
this->label2->Text = L"label2";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(123, 22);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(35, 13);
this->label3->TabIndex = 4;
this->label3->Text = L"label3";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(41, 45);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(35, 13);
this->label4->TabIndex = 5;
this->label4->Text = L"label4";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(82, 45);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(35, 13);
this->label5->TabIndex = 6;
this->label5->Text = L"label5";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(123, 68);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(35, 13);
this->label6->TabIndex = 7;
this->label6->Text = L"label6";
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(41, 68);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(35, 13);
this->label7->TabIndex = 8;
this->label7->Text = L"label7";
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(82, 68);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(35, 13);
this->label8->TabIndex = 9;
this->label8->Text = L"label8";
//
// label9
//
this->label9->AutoSize = true;
this->label9->Location = System::Drawing::Point(123, 45);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(35, 13);
this->label9->TabIndex = 10;
this->label9->Text = L"label9";
this->label9->Click += gcnew System::EventHandler(this, &Form1::label9_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(216, 210);
this->Controls->Add(this->label9);
this->Controls->Add(this->label8);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"frmMain";
this->Text = L"Tic Tac Toe";
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void label9_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}

int void main()
{
int board [] = { label1, label2, label3, label4, label5, label6, label7, label8, label9 };


}

i didnt realy write much i only got to the array rest is just forum code. Am i doing this wrong?
Last edited on
Topic archived. No new replies allowed.