public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public double jia(double a,double b)
{
return a + b;
}
public double jian(double a, double b)
{
return a - b;
}
public double cheng(double a, double b)
{
return a * b;
}
public double chu(double a, double b)
{
return a / b;
}
public double mo(double a, double b)
{
return a % b;
}
private void button1_Click(object sender, EventArgs e)
{
double a = 100;
double b = 50;
// string[] opt = new string[] { "+", "-", "*", "/", "%" };
// string[] opfun = new string[] { "jia", "jian", "cheng", "chu", "mo" };
string op = cmbOp.Text.Trim();
if (double.TryParse(txtA.Text, out a) && double.TryParse(txtB.Text, out b))
{
double c = 0d;
if (op == "+")
c = jia(a, b);
else if (op == "-")
c = jian(a, b);
else if (op == "*")
c = cheng(a, b);
else if (op == "/")
c = chu(a, b);
else if (op == "%")
{
c = mo(a, b);
}
else
c = 0;
MessageBox.Show($"{a}{op}{b}={c}", "运算");
}
else
{
MessageBox.Show("填写错误!");
}
}
private void Form1_Load(object sender, EventArgs e)
{
txtA.Text = "100";
txtB.Text = "50";
}
}


