100分急求用c#窗体程序做一个简单的四则运算界面
我们老师说用textbox或者listbox写,我也不知道该怎么写,自己做了个简单的界面不知对不对,求各位前辈提供一下你们的代码或思路~~谢谢!我的邮箱是64675336...
我们老师说用textbox或者listbox写,我也不知道该怎么写,自己做了个简单的界面不知对不对,求各位前辈提供一下你们的代码或思路~~谢谢!我的邮箱是646753363@qq.com
展开
展开全部
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 Algorithm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
char[] symbol=new char[]{'+','-','*','/'};
for (int i = 0; i < symbol.Length; i++)
{
comboBox1.Items.Add(symbol[i]);
}
}
private void button1_Click(object sender, EventArgs e)
{
double n1, n2;
n1 = Convert.ToDouble(textBox1.Text);
n2 = Convert.ToDouble(textBox2.Text);
textBox3.Text = _algorithm((char)comboBox1.SelectedItem, n1, n2);
}
private string _algorithm(char symbol,double n1, double n2)
{
string result="";
switch (symbol)
{
case '+':
result = (n1 + n2).ToString();
break;
case '-':
result = (n1 - n2).ToString();
break;
case '*':
result = (n1 * n2).ToString();
break;
case '/':
result = n2==0?"除数不能为零。":(n1 / n2).ToString();
break;
default:
break;
}
return result;
}
}
}
展开全部
已发 operation by 56lea
private void btn_get_Click(object sender, EventArgs e)
{
if (tb_n1.Text.Trim().Length < 1) return;
if (tb_n2.Text.Trim().Length < 1) return;
float a = Convert.ToSingle(tb_n1.Text);
float b = Convert.ToSingle(tb_n2.Text);
if(cb.Text=="+")tb_result.Text=(a+b).ToString();
else if (cb.Text == "-") tb_result.Text = (a -b).ToString();
else if (cb.Text == "*") tb_result.Text = (a * b).ToString();
else if (cb.Text == "/") tb_result.Text = (a / b).ToString();
}
private void btn_get_Click(object sender, EventArgs e)
{
if (tb_n1.Text.Trim().Length < 1) return;
if (tb_n2.Text.Trim().Length < 1) return;
float a = Convert.ToSingle(tb_n1.Text);
float b = Convert.ToSingle(tb_n2.Text);
if(cb.Text=="+")tb_result.Text=(a+b).ToString();
else if (cb.Text == "-") tb_result.Text = (a -b).ToString();
else if (cb.Text == "*") tb_result.Text = (a * b).ToString();
else if (cb.Text == "/") tb_result.Text = (a / b).ToString();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询