當前位置:編程學習大全網 - 編程語言 - 如何用c#編寫計算器代碼(只要加減乘除)?

如何用c#編寫計算器代碼(只要加減乘除)?

using System;\x0d\using System.Drawing;\x0d\using System.Collections;\x0d\using System.ComponentModel;\x0d\using System.Windows.Forms;\x0d\using System.Data;\x0d\\x0d\namespace jisuan\x0d\{\x0d\ /// \x0d\ /// Form1 的摘要說明。\x0d\ /// \x0d\ public class Form1 : System.Windows.Forms.Form\x0d\ {\x0d\ private System.Windows.Forms.TextBox textBox1;\x0d\ private System.Windows.Forms.TextBox textBox2;\x0d\ private System.Windows.Forms.TextBox textBox3;\x0d\ private System.Windows.Forms.ComboBox comboBox1;\x0d\ private System.Windows.Forms.Button button1;\x0d\ private System.Windows.Forms.Button button2;\x0d\ private System.Windows.Forms.Button button3;\x0d\ /// \x0d\ /// 必需的設計器變量。\x0d\ /// \x0d\ private System.ComponentModel.Container components = null;\x0d\\x0d\ public Form1()\x0d\ {\x0d\ //\x0d\ // Windows 窗體設計器支持所必需的\x0d\ //\x0d\ InitializeComponent();\x0d\\x0d\ //\x0d\ // TODO: 在 InitializeComponent 調用後添加任何構造函數代碼\x0d\ //\x0d\ }\x0d\\x0d\ /// \x0d\ /// 清理所有正在使用的資源。\x0d\ /// \x0d\ protected override void Dispose( bool disposing )\x0d\ {\x0d\ if( disposing )\x0d\ {\x0d\ if (components != null) \x0d\ {\x0d\ components.Dispose();\x0d\ }\x0d\ }\x0d\ base.Dispose( disposing );\x0d\ }\x0d\\x0d\ #region Windows 窗體設計器生成的代碼\x0d\ /// \x0d\ /// 設計器支持所需的方法 - 不要使用代碼編輯器修改\x0d\ /// 此方法的內容。\x0d\ /// \x0d\ private void InitializeComponent()\x0d\ {\x0d\ this.textBox1 = new System.Windows.Forms.TextBox();\x0d\ this.textBox2 = new System.Windows.Forms.TextBox();\x0d\ this.textBox3 = new System.Windows.Forms.TextBox();\x0d\ this.comboBox1 = new System.Windows.Forms.ComboBox();\x0d\ this.button1 = new System.Windows.Forms.Button();\x0d\ this.button2 = new System.Windows.Forms.Button();\x0d\ this.button3 = new System.Windows.Forms.Button();\x0d\ this.SuspendLayout();\x0d\ // \x0d\ // textBox1\x0d\ // \x0d\ this.textBox1.Location = new System.Drawing.Point(24, 72);\x0d\ this.textBox1.Name = "textBox1";\x0d\ this.textBox1.Size = new System.Drawing.Size(100, 21);\x0d\ this.textBox1.TabIndex = 0;\x0d\ this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);\x0d\ // \x0d\ // textBox2\x0d\ // \x0d\ this.textBox2.Location = new System.Drawing.Point(312, 72);\x0d\ this.textBox2.Name = "textBox2";\x0d\ this.textBox2.Size = new System.Drawing.Size(100, 21);\x0d\ this.textBox2.TabIndex = 1;\x0d\ // \x0d\ // textBox3\x0d\ // \x0d\ this.textBox3.Location = new System.Drawing.Point(448, 72);\x0d\ this.textBox3.Name = "textBox3";\x0d\ this.textBox3.Size = new System.Drawing.Size(88, 21);\x0d\ this.textBox3.TabIndex = 2;\x0d\ // \x0d\ // comboBox1\x0d\ // \x0d\ this.comboBox1.Items.AddRange(new object[] {\x0d\ "+",\x0d\ "-",\x0d\ "*",\x0d\ "/"});\x0d\ this.comboBox1.Location = new System.Drawing.Point(152, 72);\x0d\ this.comboBox1.Name = "comboBox1";\x0d\ this.comboBox1.Size = new System.Drawing.Size(121, 20);\x0d\ this.comboBox1.TabIndex = 3;\x0d\ this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);\x0d\ // \x0d\ // button1\x0d\ // \x0d\ this.button1.Location = new System.Drawing.Point(64, 184);\x0d\ this.button1.Name = "button1";\x0d\ this.button1.Size = new System.Drawing.Size(104, 32);\x0d\ this.button1.TabIndex = 4;\x0d\ this.button1.Text = "計算";\x0d\ this.button1.Click += new System.EventHandler(this.button1_Click);\x0d\ // \x0d\ // button2\x0d\ // \x0d\ this.button2.Location = new System.Drawing.Point(216, 192);\x0d\ this.button2.Name = "button2";\x0d\ this.button2.Size = new System.Drawing.Size(75, 23);\x0d\ this.button2.TabIndex = 5;\x0d\ this.button2.Text = "清除";\x0d\ this.button2.Click += new System.EventHandler(this.button2_Click);\x0d\ // \x0d\ // button3\x0d\ // \x0d\ this.button3.Location = new System.Drawing.Point(376, 192);\x0d\ this.button3.Name = "button3";\x0d\ this.button3.Size = new System.Drawing.Size(75, 23);\x0d\ this.button3.TabIndex = 6;\x0d\ this.button3.Text = "退出";\x0d\ this.button3.Click += new System.EventHandler(this.button3_Click);\x0d\ // \x0d\ // Form1\x0d\ // \x0d\ this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);\x0d\ this.ClientSize = new System.Drawing.Size(656, 366);\x0d\ this.Controls.Add(this.button3);\x0d\ this.Controls.Add(this.button2);\x0d\ this.Controls.Add(this.button1);\x0d\ this.Controls.Add(this.comboBox1);\x0d\ this.Controls.Add(this.textBox3);\x0d\ this.Controls.Add(this.textBox2);\x0d\ this.Controls.Add(this.textBox1);\x0d\ this.Name = "Form1";\x0d\ this.Text = "Form1";\x0d\ this.ResumeLayout(false);\x0d\ this.PerformLayout();\x0d\\x0d\ }\x0d\ #endregion\x0d\\x0d\ /// \x0d\ /// 應用程序的主入口點。\x0d\ /// \x0d\ [STAThread]\x0d\ static void Main() \x0d\ {\x0d\ Application.Run(new Form1());\x0d\ }\x0d\ public double jia(double a,double b)\x0d\ {\x0d\ return a+b;\x0d\ }\x0d\ public double jian(double a,double b)\x0d\ {\x0d\ return a-b;\x0d\ }\x0d\ public double cheng(double a,double b)\x0d\ {\x0d\ return a*b;\x0d\ }\x0d\ public double chu(double a,double b)\x0d\ {\x0d\ return a/b;\x0d\ }\x0d\\x0d\private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)\x0d\ {\x0d\\x0d\ }\x0d\\x0d\ private void textBox1_TextChanged(object sender, System.EventArgs e)\x0d\ {\x0d\\x0d\ }\x0d\\x0d\ private void button1_Click(object sender, System.EventArgs e)\x0d\ {\x0d\ string i=this.comboBox1.SelectedItem.ToString();\x0d\\x0d\ switch(i)\x0d\ {\x0d\ \x0d\ case "+":this.textBox3.Text=this.jia(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();\x0d\ \x0d\ break;\x0d\\x0d\ case "-":this.textBox3.Text=this.jian(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();\x0d\ break;\x0d\ case "*":this.textBox3.Text=this.cheng(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();\x0d\ break;\x0d\ case"/" :this.textBox3.Text=this.chu(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();\x0d\ break;\x0d\ }\x0d\\x0d\ }\x0d\\x0d\ private void button2_Click(object sender, System.EventArgs e)\x0d\ {\x0d\ this.textBox1.Text=null;\x0d\ this.textBox2.Text=null;\x0d\ this.textBox3.Text = null;\x0d\ }\x0d\\x0d\ private void button3_Click(object sender, EventArgs e)\x0d\ {\x0d\ \x0d\ //this.Hide();\x0d\ Application.Exit();\x0d\ //this.Close();\x0d\ \x0d\ }\x0d\ }\x0d\}

  • 上一篇:南京工程學院在哪
  • 下一篇:國內十大LED照明燈具品牌有哪些?
  • copyright 2024編程學習大全網