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 StudentForm { public partial class JiSuanQi : Form { private decimal JieGuo; private string YunSuanFu; public JiSuanQi() { InitializeComponent(); } private void JiaShuzi(string shuzi) { if (txtshuru.Text == "0") { txtshuru.Text = shuzi; } else { txtshuru.Text += shuzi; } } private void JiaYunSuanfu(string yunsuanfu) { if (txtjisuanshi.Text.Trim().Length == 0 && txtshuru.Text == "0") { label1.Text = "请先输入数字。"; } else { if (YunSuanFu == "+") { JieGuo += decimal.Parse(txtshuru.Text.Trim()); } else if (YunSuanFu == "-") { JieGuo -= decimal.Parse(txtshuru.Text.Trim()); } else if (YunSuanFu == "*") { JieGuo *= decimal.Parse(txtshuru.Text.Trim()); } else if (YunSuanFu == "/") { JieGuo /= decimal.Parse(txtshuru.Text.Trim()); } else if (YunSuanFu == "%") { JieGuo %= decimal.Parse(txtshuru.Text.Trim()); } else { JieGuo = decimal.Parse(txtshuru.Text.Trim()); } txtjisuanshi.Text += txtshuru.Text; txtjisuanshi.Text += yunsuanfu; YunSuanFu = yunsuanfu; txtshuru.Text = "0"; } } private void btndeng_Click(object sender, EventArgs e) { JiaYunSuanfu(btndeng.Text); txtshuru.Text = JieGuo.ToString(); } #region==数字button点击事件== private void btnling_Click(object sender, EventArgs e) { JiaShuzi(btnling.Text); } private void btnyi_Click(object sender, EventArgs e) { JiaShuzi(btnyi.Text); } private void btner_Click(object sender, EventArgs e) { JiaShuzi(btner.Text); } private void btnsan_Click(object sender, EventArgs e) { JiaShuzi(btnsan.Text); } private void btnsi_Click(object sender, EventArgs e) { JiaShuzi(btnsi.Text); } private void btnwu_Click(object sender, EventArgs e) { JiaShuzi(btnwu.Text); } private void btnliu_Click(object sender, EventArgs e) { JiaShuzi(btnliu.Text); } private void btnqi_Click(object sender, EventArgs e) { JiaShuzi(btnqi.Text); } private void btnba_Click(object sender, EventArgs e) { JiaShuzi(btnba.Text); } private void btnjiu_Click(object sender, EventArgs e) { JiaShuzi(btnjiu.Text); } #endregion private void btnClear_Click(object sender, EventArgs e) { txtshuru.Text = "0"; } private void btndian_Click(object sender, EventArgs e) { if (txtshuru.Text.Contains(".")) { label1.Text = "小数点只能输入一个"; } else { txtshuru.Text += "."; } } #region==运算符点击事件== private void btnjia_Click(object sender, EventArgs e) { JiaYunSuanfu(btnjia.Text); } private void btnjian_Click(object sender, EventArgs e) { JiaYunSuanfu(btnjian.Text); } private void btncheng_Click(object sender, EventArgs e) { JiaYunSuanfu(btncheng.Text); } private void btnchu_Click(object sender, EventArgs e) { JiaYunSuanfu(btnchu.Text); } private void btnmo_Click(object sender, EventArgs e) { JiaYunSuanfu(btnmo.Text); } #endregion private void btnchexiao_Click(object sender, EventArgs e) { txtshuru.Text = txtshuru.Text.Substring(0, txtshuru.Text.Length - 1); } } }
时间: 2024-11-08 15:12:52