namespace 计算器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double num1 = Convert.ToDouble(textBox1.Text);
double num2 = Convert.ToDouble(textBox2.Text);
string type = comboBox1.SelectedItem .ToString();
if (type == "+")
{
double num = num1 + num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="-")
{
double num = num1 - num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="×")
{
double num = num1 * num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="÷")
{
double num = num1 / num2;
string num3 = num.ToString();
label1.Text = num3;
}
if (type=="%")
{
double num = num1 % num2;
string num3 = num.ToString();
label1.Text = num3;
}
}
}
}
C#实现简单计算(winform框架)
最新推荐文章于 2025-06-05 08:58:29 发布