0% found this document useful (0 votes)
6 views12 pages

Assig

The document contains the source code for two Windows Forms applications: a Calculator and a Tic Tac Toe game. The Calculator allows basic arithmetic operations and trigonometric functions, while the Tic Tac Toe game enables two players to play against each other, checking for wins or draws. Both applications utilize event-driven programming with button click events to perform actions.

Uploaded by

Abdul Sattar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

Assig

The document contains the source code for two Windows Forms applications: a Calculator and a Tic Tac Toe game. The Calculator allows basic arithmetic operations and trigonometric functions, while the Tic Tac Toe game enables two players to play against each other, checking for wins or draws. Both applications utilize event-driven programming with button click events to perform actions.

Uploaded by

Abdul Sattar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Calculator

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 Calculator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int fnum;
int snum;
char op;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += '1';
}

private void button2_Click(object sender, EventArgs e)


{
textBox1.Text += '2';
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Text += '3';
}

private void button6_Click(object sender, EventArgs e)


{
textBox1.Text += '6';
}

private void button5_Click(object sender, EventArgs e)


{
textBox1.Text += '5';
}

private void button4_Click(object sender, EventArgs e)


{
textBox1.Text += '4';
}

private void button9_Click(object sender, EventArgs e)


{
textBox1.Text += '9';
}

private void button8_Click(object sender, EventArgs e)


{
textBox1.Text += '8';
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += '7';
}

private void button12_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
op = '*';
}

private void button11_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
op = '+';
}

private void button10_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
op = '-';
}

private void button15_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
op = '/';
}

private void button14_Click(object sender, EventArgs e)


{
textBox1.Text = "";
}

private void button18_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Text = Convert.ToString(Math.Sin(fnum));
}
private void button17_Click(object sender, EventArgs e)
{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Text = Convert.ToString(Math.Cos(fnum));
}

private void button16_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Text = Convert.ToString(Math.Tan(fnum));
}

private void button20_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Text = Convert.ToString(Math.Sqrt(fnum));
}

private void button21_Click(object sender, EventArgs e)


{
fnum = Convert.ToInt32(textBox1.Text);
textBox1.Text = "";
textBox1.Text = Convert.ToString(fnum*fnum);
}

private void button19_Click(object sender, EventArgs e)


{
snum = Convert.ToInt32(textBox1.Text);
if (op == '*')
{
textBox1.Text = Convert.ToString(fnum * snum);
}
else if (op == '+')
{
textBox1.Text = Convert.ToString(fnum + snum);
}
else if (op == '-')
{
textBox1.Text = Convert.ToString(fnum - snum);
}
else if (op == '/')
{
textBox1.Text = Convert.ToString(fnum / snum);
}

private void button13_Click(object sender, EventArgs e)


{

private void button22_Click(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{

}
}
}

Tic Tac Toe


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 Tic_Tac
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string symbol;
int count = 0;

private void button11_Click(object sender, EventArgs e)


{
symbol = "X";
}

private void button10_Click(object sender, EventArgs e)


{
symbol = "O";
}

private void button1_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button1.Text = symbol;
button1.BackColor = Color.PaleGoldenrod;
symbol = "O";
}
else
{
button1.Text = symbol;
button1.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}

private void button2_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button2.Text = symbol;
button2.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button2.Text = symbol;
button2.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}

private void button3_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button3.Text = symbol;
button3.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button3.Text = symbol;
button3.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}

private void button6_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button6.Text = symbol;
button6.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button6.Text = symbol;
button6.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}

private void button5_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button5.Text = symbol;
button5.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button5.Text = symbol;
button5.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}
private void button4_Click(object sender, EventArgs e)
{
if (symbol == "X")
{
button4.Text = symbol;
button4.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button4.Text = symbol;
button4.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}

private void button9_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button9.Text = symbol;
button9.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button9.Text = symbol;
button9.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}

private void button8_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button8.Text = symbol;
button8.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button8.Text = symbol;
button8.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}

private void button7_Click(object sender, EventArgs e)


{
if (symbol == "X")
{
button7.Text = symbol;
button1.BackColor = Color.PaleGoldenrod;
symbol = "O";

}
else
{
button7.Text = symbol;
button7.BackColor = Color.Coral;
symbol = "X";

}
count++;
check();
}
void check()
{
if (count >= 5)
{

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"&&
button6.Text=="X"&&button9.Text=="X")||
(button2.Text == "X" && button5.Text == "X"
&& button8.Text == "X")||
(button3.Text == "X" && button4.Text == "X"
&& button7.Text == "X")||
(button1.Text == "X" && button5.Text == "X"
&& button7.Text == "X")||
(button3.Text == "X" && button5.Text == "X"
&& button9.Text == "X"))
{
MessageBox.Show("X Won");
}
else 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" && button6.Text ==
"O" && button9.Text == "O") ||
(button2.Text == "O" && button5.Text == "O"
&& button8.Text == "O") ||
(button3.Text == "O" && button4.Text == "O"
&& button7.Text == "O")||
(button1.Text == "O" && button5.Text == "O"
&& button7.Text == "O")||
(button3.Text == "O" && button5.Text == "O"
&& button9.Text == "O"))
{
MessageBox.Show("O Won");
}

}
else
{
if (count == 9)
{
MessageBox.Show("Draw");
}
}
}

private void Form1_Load(object sender, EventArgs e)


{

}
private void button12_Click(object sender, EventArgs e)
{
button1.Text = "";
button1.BackColor = Color.Gray;
button2.Text = "";
button2.BackColor = Color.Gray;
button3.Text = "";
button3.BackColor = Color.Gray;
button4.Text = "";
button4.BackColor = Color.Gray;
button5.Text = "";
button5.BackColor = Color.Gray;
button6.Text = "";
button6.BackColor = Color.Gray;
button7.Text = "";
button7.BackColor = Color.Gray;
button8.Text = "";
button8.BackColor = Color.Gray;
button9.Text = "";
button9.BackColor = Color.Gray;
count = 0;
}

private void label1_Click(object sender, EventArgs e)


{

}
}
}

You might also like