Winform--계산기
25218 단어 WinForm
namespace 2._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool Isok = true;// , ( )
private string Biaodashi; // ( )
private decimal Sum;// ( )
private string Preyunsuanfu;//
private decimal d2;//
private void button32_Click(object sender, EventArgs e)//
{
Button btn = (Button) sender; //sender ,
if (Isok) //
{
textBox2.Text = btn.Text; //
Isok = false;// Isok false : , , else
d2 = decimal.Parse(textBox2.Text);
}
else
{
textBox2.Text = textBox2.Text + btn.Text;// ,
}
}
private void button36_Click(object sender, EventArgs e)//0
{
Button btn = (Button)sender; //sender ,
if (Isok) //
{
textBox2.Text = btn.Text; //
}
else
{
textBox2.Text = textBox2.Text + btn.Text;// ,
}
}
private void button44_Click(object sender, EventArgs e)//
{
Button btn = (Button)sender;//sender ,
string yunsuanfu = btn.Text; // yunsuanfu;
if (Preyunsuanfu == null)
{
Biaodashi = textBox2.Text;
Sum = decimal.Parse(textBox2.Text);
}
else
{
if (!Isok) // , . .
{ // !Isok , .
if (Preyunsuanfu == "+") //
{
Sum = Sum + decimal.Parse(textBox2.Text);//
}
if (Preyunsuanfu == "-")
{
Sum = Sum - decimal.Parse(textBox2.Text);
}
if (Preyunsuanfu == "*")
{
Sum = Sum * decimal.Parse(textBox2.Text);
}
if (Preyunsuanfu == "/")
{
Sum = Sum / decimal.Parse(textBox2.Text);
}
if (Preyunsuanfu == "%")
{
Sum = Sum % decimal.Parse(textBox2.Text);
}
Biaodashi = Biaodashi + Preyunsuanfu + textBox2.Text;// + +
textBox2.Text = Sum.ToString(); //
}
}
textBox1.Text = Biaodashi + yunsuanfu;// +
Preyunsuanfu = yunsuanfu;// yunsuanfu ;
Isok = true; // Isok ture,
}
private void button8_Click(object sender, EventArgs e) //
{ //
textBox1.Text = "";
textBox2.Text = "0";
Isok = true;
Preyunsuanfu = null;
Sum = 0;
Biaodashi = "";
d2 = 0;
}
private void button6_Click(object sender, EventArgs e)//
{
if (!Isok) //
{
if (textBox2.Text.Length == 1)// 1
{
textBox2.Text = "0"; // 0
Isok = true;// 0, Isok true. 0 , 。
}
else
{
textBox2.Text = textBox2.Text.Substring(0, textBox2.Text.Length - 1);
}
}
}
private void button28_Click(object sender, EventArgs e) //
{
if(!textBox2.Text.Contains("."))//
{
textBox2.Text = textBox2.Text + ".";
Isok = false;//
}
}
// private bool d3 = true;//
private void button30_Click(object sender, EventArgs e) //
{
Button btn = (Button)sender;
textBox1.Text = ""; //
//
if (Preyunsuanfu == "+") //
{
Sum = Sum + decimal.Parse(textBox2.Text);//
}
if (Preyunsuanfu == "-")
{
Sum = Sum - decimal.Parse(textBox2.Text);
}
if (Preyunsuanfu == "*")
{
Sum = Sum * decimal.Parse(textBox2.Text);
}
if (Preyunsuanfu == "/")
{
Sum = Sum / decimal.Parse(textBox2.Text);
}
if (Preyunsuanfu == "%")
{
Sum = Sum % decimal.Parse(textBox2.Text);
}
textBox2.Text = Sum.ToString();//
//
Isok = true;
Biaodashi = "";
Preyunsuanfu = null;
Sum = d2+decimal.Parse(textBox2.Text);
//
}
private void button9_Click(object sender, EventArgs e) //
{
if (!Isok) // ,
{
if (decimal.Parse(textBox2.Text) > 0)
{
textBox2.Text = "-" + textBox2.Text;//
}
else
{
textBox2.Text = textBox2.Text.Substring(1);//
}
}
}
private string m;
private void button4_Click(object sender, EventArgs e) //M+ textbox2 M+
{
if (textBox2.Text == "0")
{
}
else
{
textBox3.Text = "M";
}
m = textBox2.Text;
}
private void button2_Click(object sender, EventArgs e)//MR MR M+ ;
{
textBox2.Text = m;
}
private void button5_Click(object sender, EventArgs e)//M- M+
{
if(!Isok)//
{
Sum=decimal.Parse(m)-decimal.Parse(textBox2.Text);
textBox2.Text = Sum.ToString();
}
}
private double ss;
private void button10_Click(object sender, EventArgs e)//
{
ss = Math.Sqrt(double.Parse(textBox2.Text));
textBox1.Text = "sqrt" + "(" + textBox2.Text + ")";
textBox2.Text = ss.ToString();
Isok = true;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private double fenshu;
private void button41_Click(object sender, EventArgs e)//
{
fenshu = 1 / double.Parse(textBox2.Text);
textBox1.Text = "reciproc" + "("+textBox2.Text+")";//
textBox2.Text = fenshu.ToString();//
}
private void button7_Click(object sender, EventArgs e)//CE C
{
//
textBox1.Text = "";
textBox2.Text = "0";
Isok = true;
Preyunsuanfu = null;
Sum = 0;
Biaodashi = "";
}
private void button1_Click(object sender, EventArgs e) //MC M+
{
textBox3.Text = "";
m = "0";
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C# Excel 템플릿 내보내기(Word 등)프로젝트에서 Excel, Word, pdf 등 템플릿 내보내기를 자주 사용해야 합니다. 다음은 자신이 정리한 간단한 버전의 템플릿 내보내기입니다. 복잡한 내보내기와 유사합니다. 조금만 수정하면 됩니다.다음 내보내기 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.