199 lines
4.9 KiB
C#
199 lines
4.9 KiB
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 WindowsFormsApp1
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void button_0_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "0";
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "1";
|
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "2";
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "3";
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "4";
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "5";
|
|
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "6";
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "7";
|
|
}
|
|
|
|
private void button8_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "8";
|
|
}
|
|
|
|
private void button9_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = textBox1.Text + "9";
|
|
}
|
|
|
|
|
|
|
|
|
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
private void division_Click_1(object sender, EventArgs e)
|
|
{
|
|
Dataread();
|
|
Data.mode = '/';
|
|
}
|
|
|
|
|
|
private void multiplication_Click(object sender, EventArgs e)
|
|
{
|
|
Dataread();
|
|
Data.mode = '*';
|
|
}
|
|
|
|
private void substraction_Click(object sender, EventArgs e)
|
|
{
|
|
Dataread();
|
|
Data.mode = '-';
|
|
}
|
|
|
|
private void addition_Click(object sender, EventArgs e)
|
|
{
|
|
Dataread();
|
|
Data.mode = '+';
|
|
}
|
|
|
|
private void enter_Click(object sender, EventArgs e)
|
|
{
|
|
ModeCase();
|
|
}
|
|
|
|
|
|
|
|
private void point_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text += ',';
|
|
}
|
|
|
|
private void clear_Click(object sender, EventArgs e)
|
|
{
|
|
textBox1.Clear();
|
|
Data.mode = ' ';
|
|
ModeCase();
|
|
}
|
|
|
|
public void Dataread()
|
|
{
|
|
bool eredmeny = textBox1.Text.Any(x => !char.IsLetter(x));
|
|
if (eredmeny)
|
|
{
|
|
Data.x = Convert.ToDouble(textBox1.Text);
|
|
textBox1.Clear();
|
|
}
|
|
else
|
|
{
|
|
textBox1.Text = "";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void ModeCase()
|
|
{
|
|
switch (Data.mode)
|
|
{
|
|
case '+':
|
|
Data.y = Convert.ToDouble(textBox1.Text);
|
|
textBox1.Clear();
|
|
Data.ans = Data.x + Data.y;
|
|
textBox1.Text = Data.ans.ToString();
|
|
break;
|
|
case '-':
|
|
Data.y = Convert.ToDouble(textBox1.Text);
|
|
textBox1.Clear();
|
|
Data.ans = Data.x - Data.y;
|
|
textBox1.Text = Data.ans.ToString();
|
|
break;
|
|
case '/':
|
|
Data.y = Convert.ToDouble(textBox1.Text);
|
|
textBox1.Clear();
|
|
if (Data.x != 0)
|
|
{
|
|
Data.ans = Data.x / Data.y;
|
|
textBox1.Text = Data.ans.ToString();
|
|
}
|
|
else
|
|
{
|
|
textBox1.Text = "Error";
|
|
}
|
|
break;
|
|
case '*':
|
|
Data.y = Convert.ToDouble(textBox1.Text);
|
|
textBox1.Clear();
|
|
Data.ans = Data.x * Data.y;
|
|
textBox1.Text = Data.ans.ToString();
|
|
break;
|
|
case ' ':
|
|
Data.x = 0.0;
|
|
Data.y = 0.0;
|
|
textBox1.Clear();
|
|
Data.ans = 0.0;
|
|
textBox1.Text = "";
|
|
break;
|
|
default:
|
|
textBox1.Text = "Error";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class Data
|
|
{
|
|
public static double x;
|
|
public static double y;
|
|
|
|
public static double ans;
|
|
|
|
public static char mode;
|
|
}
|
|
}
|