在C#里面写一个计算器的代码谁能告诉我一下。
你好: 代码如下,希望对你有帮助! private void 平方根_Click(object sender, EventArgs e) { double i = Convert.ToDouble(textBox1.Text); //将文本框的值转换为Double型 textBox1.Text = Math.Sqrt(i).ToString(); //将计算结果转换为字符串输入文本框中 } private void 平方_Click(object sender, EventArgs e) { double i = Convert.ToDouble(textBox1.Text); textBox1.Text = (i*i).ToString(); }
http://www.cnblogs.com/linshuangxi/p/3417068.html
这个网址有完整的代码,如果你想学习怎么做,它也有步骤
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.IO;
namespace 计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
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;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
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 button10;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Button button19;
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
private System.Windows.Forms.PictureBox pictureBox1;
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 );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button11 = new System.Windows.Forms.Button();
this.button12 = new System.Windows.Forms.Button();
this.button13 = new System.Windows.Forms.Button();
this.button14 = new System.Windows.Forms.Button();
this.button15 = new System.Windows.Forms.Button();
this.button16 = new System.Windows.Forms.Button();
this.button17 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.button18 = new System.Windows.Forms.Button();
this.button19 = new System.Windows.Forms.Button();
this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(112, 32);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(240, 29);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// label1
//
this.label1.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(24, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 40);
this.label1.TabIndex = 1;
this.label1.Text = "结果";
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 168);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(40, 32);
this.button1.TabIndex = 3;
this.button1.Text = "1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(88, 168);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(40, 32);
this.button2.TabIndex = 4;
this.button2.Text = "2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(152, 168);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(40, 32);
this.button3.TabIndex = 5;
this.button3.Text = "3";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(24, 216);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(40, 32);
this.button4.TabIndex = 6;
this.button4.Text = "4";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(88, 216);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(40, 32);
this.button5.TabIndex = 7;
this.button5.Text = "5";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(152, 216);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(40, 32);
this.button6.TabIndex = 8;
this.button6.Text = "6";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(24, 264);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(40, 32);
this.button7.TabIndex = 9;
this.button7.Text = "7";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.Location = new System.Drawing.Point(88, 264);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(40, 32);
this.button8.TabIndex = 10;
this.button8.Text = "8";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button9
//
this.button9.Location = new System.Drawing.Point(152, 264);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(40, 32);
this.button9.TabIndex = 11;
this.button9.Text = "9";
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button11
//
this.button11.Location = new System.Drawing.Point(152, 320);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(40, 32);
this.button11.TabIndex = 13;
this.button11.Text = "=";
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// button12
//
this.button12.Location = new System.Drawing.Point(152, 120);
this.button12.Name = "button12";
this.button12.Size = new System.Drawing.Size(40, 32);
this.button12.TabIndex = 14;
this.button12.Text = "/";
this.button12.Click += new System.EventHandler(this.button12_Click);
//
// button13
//
this.button13.Location = new System.Drawing.Point(208, 120);
this.button13.Name = "button13";
this.button13.Size = new System.Drawing.Size(40, 32);
this.button13.TabIndex = 15;
this.button13.Text = "*";
this.button13.Click += new System.EventHandler(this.button13_Click);
//
// button14
//
this.button14.Location = new System.Drawing.Point(208, 168);
this.button14.Name = "button14";
this.button14.Size = new System.Drawing.Size(40, 32);
this.button14.TabIndex = 16;
this.button14.Text = "-";
this.button14.Click += new System.EventHandler(this.button14_Click);
//
// button15
//
this.button15.Location = new System.Drawing.Point(208, 216);
this.button15.Name = "button15";
this.button15.Size = new System.Drawing.Size(40, 32);
this.button15.TabIndex = 17;
this.button15.Text = "+";
this.button15.Click += new System.EventHandler(this.button15_Click);
//
// button16
//
this.button16.Location = new System.Drawing.Point(24, 120);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(104, 32);
this.button16.TabIndex = 18;
this.button16.Text = "播放音乐";
this.button16.Click += new System.EventHandler(this.button16_Click);
//
// button17
//
this.button17.Location = new System.Drawing.Point(208, 264);
this.button17.Name = "button17";
this.button17.Size = new System.Drawing.Size(40, 88);
this.button17.TabIndex = 19;
this.button17.Text = "C";
this.button17.Click += new System.EventHandler(this.button17_Click);
//
// button10
//
this.button10.Location = new System.Drawing.Point(24, 320);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(56, 32);
this.button10.TabIndex = 20;
this.button10.Text = "0";
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button18
//
this.button18.Location = new System.Drawing.Point(304, 312);
this.button18.Name = "button18";
this.button18.Size = new System.Drawing.Size(80, 40);
this.button18.TabIndex = 21;
this.button18.Text = "关闭";
this.button18.Click += new System.EventHandler(this.button18_Click);
//
// button19
//
this.button19.Location = new System.Drawing.Point(88, 320);
this.button19.Name = "button19";
this.button19.Size = new System.Drawing.Size(40, 32);
this.button19.TabIndex = 24;
this.button19.Text = ".";
this.button19.Click += new System.EventHandler(this.button19_Click);
//
// axWindowsMediaPlayer1
//
this.axWindowsMediaPlayer1.Enabled = true;
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(272, 80);
this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(112, 168);
this.axWindowsMediaPlayer1.TabIndex = 25;
this.axWindowsMediaPlayer1.Enter += new System.EventHandler(this.axWindowsMediaPlayer1_Enter);
//
// pictureBox1
//
this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
this.pictureBox1.Location = new System.Drawing.Point(272, 184);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(112, 104);
this.pictureBox1.TabIndex = 28;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(10, 22);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(408, 398);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.axWindowsMediaPlayer1);
this.Controls.Add(this.button19);
this.Controls.Add(this.button18);
this.Controls.Add(this.button10);
this.Controls.Add(this.button17);
this.Controls.Add(this.button16);
this.Controls.Add(this.button15);
this.Controls.Add(this.button14);
this.Controls.Add(this.button13);
this.Controls.Add(this.button12);
this.Controls.Add(this.button11);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Font = new System.Drawing.Font("楷体_GB2312", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "Form1";
this.Text = "计算器";
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button2_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button3_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button4_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button5_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button6_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button7_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button8_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button9_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button10_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button19_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text+=btn.Text;
}
private void button12_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text=textBox1.Text+" "+btn.Text+" ";
}
private void button13_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text=textBox1.Text+" "+btn.Text+" ";
}
private void button14_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text=textBox1.Text+" "+btn.Text+" ";
}
private void button15_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
textBox1.Text=textBox1.Text+" "+btn.Text+" ";
}
private void button16_Click(object sender, System.EventArgs e)
{
FileDialog ofDialog=new OpenFileDialog();
ofDialog.AddExtension=true;
ofDialog.CheckFileExists=true;
ofDialog.CheckPathExists=true;
ofDialog.Filter="VCD文件(*.dat)|*.dat|Audio文件(*.avi)|*.avi|WAV文件(*.wav)|*.wav|MP3文件(*.mp3)|*.mp3|所有文件(*.*)|*.*";
ofDialog.FilterIndex=4;
if(ofDialog.ShowDialog()==DialogResult.OK)
{
this.axWindowsMediaPlayer1.URL=ofDialog.FileName;
}
}
private void button17_Click(object sender, System.EventArgs e)
{
textBox1.Text="";
}
private void button18_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button11_Click(object sender,System.EventArgs e)
{
Single r=0;
string t=textBox1.Text;
int space = t.IndexOf(' ');
string S1=t.Substring(0,space);
char op=Convert.ToChar(t.Substring(space+1,1));
string S2=t.Substring(space+3);
Single arg1=Convert.ToSingle(S1);
Single arg2=Convert.ToSingle(S2);
switch(op)
{
case '+':
r=arg1+arg2;
break;
case '-':
r=arg1-arg2;
break;
case '*':
r=arg1*arg2;
break;
case '/':
if(arg2==0)
textBox1.Text="error!";
else
r=arg1/arg2;
break;
}
textBox1.Text=r.ToString();
}
private void axWindowsMediaPlayer1_Enter(object sender, System.EventArgs e)
{
}
}
}
刚学C#的时候做过一个计算器的~很简单,学编程的最好先不要看源码~自己做做试试看嘛~实在不行再参考一下~要源码的话,很多百度,狗狗一搜一大把~
c在化学中指什么意思
C在化学中有两种含义:1、表示浓度,单位为mol\/L,计算式为:C=n\/V. C=1000ρω\/M。含义:以1升溶液中所含溶质的摩尔数表示的浓度。以单位体积里所含溶质的物质的量(摩尔数)来表示溶液组成的物理量,叫作该溶质的摩尔浓度,又称该溶质物质的量浓度。溶质含量越多,浓度越大。浓度可以用一定...
c表示什么?
c表示溶液百分比,公式为:C=N\/V=(M\/M)\/[MO\/(P*1000)]=1000PW%\/M。溶液百分比浓度是指溶液所含溶质的重量的百分比。一种可溶物质溶于一种溶剂后,在该溶剂的分布密度以百分比的方式表示,称为溶液百分比浓度,常用C%来表示。溶液浓度可分为质量浓度、体积浓度和质量-体积浓度三类。体积浓度 ...
数学中c代表什么
数学中c表示复数集合。在数学计算等场合中经常使用,是作为对文字说明的省略的符号表达。集合,简称集,是数学中一个基本概念,也是集合论的主要研究对象。集合论的基本理论创立于19世纪,关于集合的最简单的说法就是在朴素集合论(最原始的集合论)中的定义,即集合是“确定的一堆东西”,集合里的“东西...
c的意思?
C是发生事故的严重性,consequences的缩写。consequences 英 ['kɑnsə,kwɛnsɪz] 美 ['kɑnsə,kwɛnsɪz]n. 后果,结果;影响(consequence的复数)短语:unintended consequences 意外后果 ; 非预期后果 ; 未预期的后果 ; 没有预计的结果 serious consequences...
c在爱情的含义
c在爱情的含义1 “C型爱情观”指的是对现代爱情关一种新的定义。在爱情中,有进有退、牵手分手的循环,已不再是个稀奇风景,而“有始有终”,在“C型爱情观”中有了崭新的定义——有开始,就必有终了之时。它的最大特点在于人们不再将青春耗损在不良关系上。C型人生取代了线型人生,俨然成为...
c在爱情的含义是什么
c在爱情的含义是什么,用各种各样的符号来代替我们想要表达的真实意思是我们对一份感情的含蓄表示,世间万物存在的意义就是我们赋予的内涵,下面分享c在爱情的含义是什么。 c在爱情的含义是什么1 C指的是现在流行的C型爱情观。 C型爱情观 “C型爱情观”指的是对现代爱情关一种新的定义。在爱情中,有进有退、...
字母c的发音规则口诀是什么?
字母c的发音规则口诀:ci、ce紧相连,c发[s]音记心间。其它形式莫忘记,c发[k]音最常见。c在字母e,i或y前面时发音[s],单词举例:city c在字母a,o或u,或者在辅音字母前发音[k],单词举例:cup c在词尾时也发[k],但后面有e,那还发[s],单词举例:music[k],grace[s]-cc在元音...
网络上C和sc是什么意思?
1、”C“是拼音“chu”的首字母,为了方便起见缩写为“C”,指的是处男、处女的意思。2、SC是superchat的缩写,是付费留言功能。这个功能最开始是YouTube2017年上线的,B站也推出了这个功能。这是一种在直播过程中连接粉丝与主播的方式,同时也可给主播带来相应的经济收益。通过这一功能,粉丝可以以明亮...
c是什么意思医学
c是什么意思医学1 它是放射科的一种检查,叫CT泌尿系造影,就是在腹盆CT的基础上进行加工重建使两侧肾脏、输尿管及膀胱显示出来,c的意思就是颈椎,比如c4就是第四颈椎 c什么意思 大写C代表 在化学中,表示碳的化学符号 在乐理中,表示:音阶中的C音 调号中于C音开始的音乐的C大调及C小调 拍子...
c c分别是什么意思
C C 在不同的场合下,可能代表不同的含义。在计算机科学中,C C 通常指的是 C++ 语言。C++ 是一种面向对象编程语言,它是 C 语言的扩展和改进。相较于 C 语言,C++ 具有更强大的编程能力和更高的抽象性,使得程序开发变得更加灵活和高效。C++ 同时也是广泛应用于游戏和图形界面开发的主流编程语言...
资命阿莫: Console.WriteLine("请输入第一个数");int a = int.Parse(Console.ReadLine());Console.WriteLine("请输入第二个数");int b = int.Parse(Console.ReadLine());Console.WriteLine("请输入运算符'+','-','*','/'");string c = ...
米脂县15290516953: 求C#做计算器的代码,最好能教教我?
资命阿莫: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;namespace calculator { /// <summary> /// Form1 的摘要说明. /// </summary> public class Form...
米脂县15290516953: 求一个c#编写的简易能运行的计算器代码 - ?
资命阿莫: 使用系统; 引用; 使用System.Linq的; 使用System.Text; 命名空间ConsoleApplication3 { ??类项目 ??? ????私有静态双C; ?????私有静态双加(INT A,INT B) ???? ??????C = A + B; ??????回报; ????} 私有...
米脂县15290516953: 用C# 制作一个简单加减成除计算器的代码 - ?
资命阿莫: using System; using System.Collections.Generic; using System.Text; namespace shangJi { class Opreation { 加法 public float Add(float num1, float num2) { return num1 + num2; } 减法 public float Sub(float num1, float num2) { return num1 - num2;...
米脂县15290516953: 请问用C#制作计算器的程序代码是什么?急用.谢谢?
资命阿莫: 这个已经有计算功能了,但记事本还没有,给你急用.因为C没有专门的字符串类型:有事再联系405719864// C语言计算器.cpp : Defines the entry point for the console application.///*注意!本程序用C编写,在VC++6.0中运行通过,如果要有记...
米脂县15290516953: 求用C#编写的简易计算器的代码?
资命阿莫: 其实在C#中和Java中的代码都是一样的 using... ..... ////在窗体上放三个 文本框 txt1\txt2\txt3----控件的名字 一个下拉列表框 slt1---控件的名字 一个Button按钮--btnRst pulic static void main(string args[]) { ..... .... 自动生成的 } public void btnRstClick(...
米脂县15290516953: C#语言编写一个简单的加减计算器 - ?
资命阿莫: Console.Write("请输入第一个数字:"); double num1 = Convert.toDouble(Console.ReadLine()); Console.Write("请输入运算符(+、-、*、/):"); string p = Console.ReadLine(); Console.Write("请输入第二个数字:"); double ...
米脂县15290516953: 速求!怎样用C#编写一个简单的计算器??? - ?
资命阿莫: 在运行里输入calc然后模仿:1会基本的c#写winform程序2 用一个static 变量记录最后一个按钮的输入符号3当2之后输入数字后只要接收运算符号就计算并显示如果你只是想要一个计...
米脂县15290516953: 用C#编写一个简易计算器,麻烦把程序写出来. - ?
资命阿莫: 同学,给你写了一个方法,你自己设计窗体写到单击事件里去吧.这里不建议用switch语句,因为这样写会很繁琐,代码可读性很差.private float getpersonalpay(float salary) { int temp=(salary-3500) / 1500; if(temp { return (salary-3500)*3; } else if(...
米脂县15290516953: 用c#语言编写一个计算器,只实现加减乘除.哪位朋友能帮忙解答一下!感激不尽! - ?
资命阿莫: /* 计算器算法 当每次安1~9的数字按键,调用一个anniu方法,在aniu方法 用是否输入运算符来判断是否是输入的是 第一个第二个值,中间在判断是否是小数的数值算法.普通值的算法是 a=a*10+i; i为传入的参数的值 小数值的算法是 a=a+i/s; s=...