设计一个windows应用程序,实现不同运算。
2013-04-24 19:50
260 查看
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
string s;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text.Length==0||textBox2.Text.Length==0)
{
MessageBox.Show("请输入数据!");
return;
}
try
{
double x = double.Parse(textBox1.Text);
double y = double.Parse(textBox2.Text);
//textBox3.Text=(x y).ToString();
switch (s)
{
case "+": textBox3.Text = (x + y).ToString(); break;
case "-": textBox3.Text = (x - y).ToString(); break;
case "*": textBox3.Text = (x * y).ToString(); break;
case "/": textBox3.Text = (x / y).ToString(); break;
default: textBox3.Text = "错误"; break;
}
}
catch(Exception ex)
{MessageBox.Show(ex.Message);}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
s = comboBox1.Text;
//MessageBox.Show(s);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
string s;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text.Length==0||textBox2.Text.Length==0)
{
MessageBox.Show("请输入数据!");
return;
}
try
{
double x = double.Parse(textBox1.Text);
double y = double.Parse(textBox2.Text);
//textBox3.Text=(x y).ToString();
switch (s)
{
case "+": textBox3.Text = (x + y).ToString(); break;
case "-": textBox3.Text = (x - y).ToString(); break;
case "*": textBox3.Text = (x * y).ToString(); break;
case "/": textBox3.Text = (x / y).ToString(); break;
default: textBox3.Text = "错误"; break;
}
}
catch(Exception ex)
{MessageBox.Show(ex.Message);}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
s = comboBox1.Text;
//MessageBox.Show(s);
}
}
}
相关文章推荐
- C#--,设计一个windows应用程序,实现不同运算。
- C#Windows 窗体设计-实现欢迎界面-显示About窗体-在托盘中写入应用程序图标
- 一个简单的实现不同权限的用户登录后看到不同的菜单设计的数据库表清单
- 设计一个计算器类Calculator,它只有一个计数的成员count。该计算器的有效范围说0~65535,实现计算器的前自增、后自增、前自减、后自减、两个计算器相加减等运算
- 一个简单的实现不同权限的用户登录后看到不同的菜单设计的数据库表清单
- 实验题7.1: 编写一个程序algo7-1.cpp,实现二叉树的各种基本运算,并在此基础上设计一个程序Main.cpp完成如下功能(b为如下图所示的一棵二叉树)
- 设计一个计算器类Claculator,它只有一个用于计数的数据成员count。该计算器的有效计数范围是0~65535,实现计数器的前自增、后自增、前自减、后自减、两个计算器相加减运算
- 设计一个时间类Time, 包括时,分,秒等私有数据成员。要求实现时间的基本运算,一个时间加上另一个时间。。
- (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) (4)设计一个测试类
- 如果系统要使用超大整数(超过long长度范围),请你设计一个数据结构来存储这种超大型数字以及设计一种算法来实现超大整数加法运算
- 如果系统要使用超大整数(超过long长度范围),请你设计一个数据结构来存储这种超大型数字以及设计一种算法来实现超大整数加法运算)
- 利用Timer控件【Timer(6.4.9)】编写C# Windows应用程序,设计一个如下效果电子时钟。
- 设计并实现用于ASP.NET一个通用的数据存取层应用程序 原作者 Paul Abarham 翻译 cwxiao888@163.com
- C#窗体-个人简历生成(自己设计并编写一个 Windows 应用程序,要求用到TextBox、GroupBox、RadioButton )
- 习题9:设计一个Windows应用程序,窗体上有一个TextBox控件、一个Button控件。
- 习题10:参照Windows系统“附件”中的“计算器”,自行编写一个简易的计算器。要求:可以实现由0~4构成的整数的加减运算。
- 一个简单的实现不同权限的用户登录后看到不同的菜单设计的数据库表清单
- 设计一个日期类Date,包括年、月、日等私有成员。要求实现日期的基本运算,例如某日期加上天数或减去天数
- 折半查找实现算法二(递归办法)PS:编译后有一个warning,但不影响结果,代码设计上应该还有些问题
- Windows Store apps开发[58]Windows 8 开发31日-第01日-一个空的应用程序