| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 474 人关注过本帖
标题:计算器
取消只看楼主 加入收藏
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
结帖率:100%
收藏
 问题点数:0 回复次数:5 
计算器
我做了个简单的计算器,但不怎样才能实现混合混算
比如1+2*3会先算2*3再+1,大家帮帮忙哦
搜索更多相关主题的帖子: 计算器 
2006-10-14 09:55
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
收藏
得分:0 
怎么上传不上来呀??

不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2006-10-14 09:56
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
收藏
得分:0 

还是发代码上来吧
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
bool x=true;
string ch;
double number1=0,number2=0,sum;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
public System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button12;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.Button button17;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Button button19;
private System.Windows.Forms.Button button20;
private System.Windows.Forms.Button button21;
private System.Windows.Forms.Button button22;
private System.Windows.Forms.Button button23;
private System.Windows.Forms.Button button24;
private System.Windows.Forms.Button button25;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2006-10-14 10:10
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
收藏
得分:0 

#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}



private void button24_Click(object sender, System.EventArgs e)
{
double x,y;
x = double.Parse (textBox1.Text );
y=x-2*x;
textBox1.Text = y.ToString () ;
}

private void button21_Click(object sender, System.EventArgs e)
{
number1 = double.Parse (textBox1.Text );
ch = button21.Text ;
x=true;
}

private void button22_Click(object sender, System.EventArgs e)
{
number1 = double .Parse (textBox1.Text) ;
if(number1<0)
{
textBox1.Text ="不能求负数的平方根!";
}
else if(number1==0)
{
textBox1.Text = number1.ToString ();
}
else
{
textBox1.Text = Math.Sqrt (number1).ToString ();
}

}

private void button23_Click(object sender, System.EventArgs e)
{
textBox1.Clear ();
double a=0;
x=true;
textBox1.Text = a.ToString ();
}

private void button20_Click(object sender, System.EventArgs e)
{
number1 = double.Parse (textBox1.Text );
sum = number1*number1;
textBox1.Text = sum.ToString ();
}

private void button19_Click(object sender, System.EventArgs e)
{
number1 = double.Parse (textBox1.Text) ;
sum=1;
for(int i =1;i<=number1;i++)
{
sum *=i;
}
textBox1.Text = sum.ToString ();
}

private void button18_Click(object sender, System.EventArgs e)
{
this.Close ();
}

private void button17_Click(object sender, System.EventArgs e)
{
number1=0;
number2=0;
ch="";
sum=0;
x=true;
textBox1.Clear ();
// textBox1.Focus ();
textBox1.Text = number1.ToString ();
}

private void button16_Click(object sender, System.EventArgs e)
{
if(ch!="")
{
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{

textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
}
number1 = double.Parse (textBox1.Text );
x=true;
ch = button16.Text ;
}

private void button14_Click(object sender, System.EventArgs e)
{
if(ch =="")
{
number1=double.Parse (textBox1.Text );
textBox1.Text = number1.ToString ();
}
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{

textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
number1 = double.Parse (textBox1.Text) ;
x=true;
ch = button14.Text ; ;
}

private void button13_Click(object sender, System.EventArgs e)
{
if(ch!="")
{
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{

textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
}

number1 = double.Parse (textBox1.Text );
x=true;
ch = button13.Text ;

}


不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2006-10-14 10:14
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
收藏
得分:0 

private void button12_Click(object sender, System.EventArgs e)
{
if(ch!="")
{
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{

textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
}

number1 = double.Parse (textBox1.Text );
ch = button12.Text ;
x = true;

}

private void button11_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button11.Text ;
}

private void button10_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button10.Text;
}

private void button9_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button9.Text ;
}

private void button8_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button8.Text ;
}

private void button7_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button7.Text ;
}

private void button6_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button6.Text ;
}

private void button5_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button5.Text ;
}

private void button4_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button4.Text ;
}

private void button3_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button3.Text ;
}

private void button2_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button2.Text ;
}

private void button1_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button1.Text ;
}

private void Form1_Load()
{

}
}
}



不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2006-10-14 10:16
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
收藏
得分:0 

上传不了图片,


不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2006-10-14 10:23
快速回复:计算器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.065193 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved