Red de conocimiento informático - Material del sitio web - ¿Cómo escribir código de calculadora en C# (solo suma, resta, multiplicación y división)?

¿Cómo escribir código de calculadora en C# (solo suma, resta, multiplicación y división)?

usando 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\ /// Descripción resumida de 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\ privado System.Windows.Forms.TextBox textBox3; \x0d\ privado System.Windows.Forms.ComboBox comboBox1; \x0d\ privado System.Windows.Forms.Button botón1; button2;\x0d\ private System.Windows.Forms.Button button3;\x0d\ /// \x0d\ /// Variable de diseñador requerida. \x0d\ /// \x0d\ private System.ComponentModel.Container componentes = null; \x0d\\x0d\ public Form1()\x0d\ {\x0d\ //\x0d\ // Windows Forms Designer admite todos los Required\ x0d\ //\x0d\ InitializeComponent(); \x0d\\x0d\ //\x0d\ // TODO: Agregar cualquier código de constructor después de la llamada a InitializeComponent \x0d\ //\x0d\ }\x0d\ \x0d\ / // \x0d\ /// Limpiar todos los recursos en uso. \x0d\ /// \x0d\ protected override void Dispose( bool disposing )\x0d\ {\x0d\ if( disposing )\x0d\ {\x0d\ if (components != null) \x0d\ {\x0d\ componentes .Dispose();\x0d\ }\x0d\ }\x0d\ base.Dispose( disposing );\x0d\ }\x0d\\x0d\ #código de región generado por Windows Forms Designer\x0d\ /// \ x0d\ /// El diseñador admite el método requerido; no utilice el editor de código para modificar \x0d\ /// el contenido de este método.

\x0d\ /// \x0d\ private void InitializeComponent()\x0d\ {\x0d\ this.textBox1 = nuevo System.Windows.Forms.TextBox(); \x0d\ this.textBox2 = nuevo System.Windows.Forms. TextBox();\x0d\ this.textBox3 = nuevo System.Windows.Forms.TextBox();\x0d\ this.comboBox1 = nuevo System.Windows.Forms.ComboBox();\x0d\ this.button1 = nuevo Sistema. Windows.Forms.Button();\x0d\ this.button2 = nuevo System.Windows.Forms.Button();\x0d\ this.button3 = nuevo 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 = nuevo System.Drawing.Size(100, 21);\x0d\ this.textBox1.TabIndex = 0;\x0d\ this.textBox1.TextChanged = nuevo System.EventHandler(este .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 = nuevo sistema

em.Drawing.Point(448, 72);\x0d\ this.textBox3.Name = "textBox3";\x0d\ this.textBox3.Size = nuevo System.Drawing.Size(88, 21);\x0d\ this. textBox3.TabIndex = 2;\x0d\ // \x0d\ // comboBox1\x0d\ // \x0d\ this.comboBox1.Items.AddRange(nuevo objeto[] {\x0d\ " ",\x0d\ "-" ,\x0d\ "*",\x0d\ "/"});\x0d\ this.comboBox1.Location = new System.Drawing.Point(152, 72);\x0d\ this.comboBox1.Name = "comboBox1" ;\x0d\ this.comboBox1.Size = nuevo System.Drawing.Size(121, 20);\x0d\ this.comboBox1.TabIndex = 3;\x0d\ this.comboBox1.SelectedIndexChanged = nuevo System.EventHandler(this.comboBox1_SelectedIndexChanged );\x0d\ // \x0d\ // botón1\x0d\ // \x0d\ this.button1.Location = new System.Drawing.Point(64, 184; \x0d\ this.button1.Name = "botón1); ";\x0d\ this.button1.Size = new System.Drawing.Size(104, 32);\x0d\ this.button1.TabIndex = 4;\x0d\ this.button1.Text = "Calcular";\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 = "botón2";\x0d\

this.button2.Size = new System.Drawing.Size(75, 23);\x0d\ this.button2.TabIndex = 5;\x0d\ this.button2.Text = "Borrar";\x0d\ this.button2.Click = nuevo System.EventHandler(this.button2_Click);\x0d\ // \x0d\ // botón3\x0d\ // \x0d\ this.button3.Location = nuevo System.Drawing.Point(376, 192);\x0d \ this.button3.Name = "button3"; \x0d\ this.button3.Size = nuevo System.Drawing.Size(75, 23); \x0d\ this.button3.TabIndex = 6; Text = "Salir";\x0d\ this.button3.Click = new System.EventHandler(this.button3_Click);\x0d\ // \x0d\ // Form1\x0d\ // \x0d\ this.AutoScaleBaseSize = nuevo Sistema .Drawing.Size(6, 14);\x0d\ this.ClientSize = nuevo 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.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\ /// El punto de entrada principal de la aplicación.

\x0d\ /// \x0d\ [STAThread]\x0d\ static void Main() \x0d\ {\x0d\ Application.Run(new Form1()); \x0d\ }\x0d\ public double jia(doble a , doble 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(doble a, doble b)\x0d\ {\x0d\ return a*b;\x0d\ }\x0d\ public double chu(doble a, doble b)\x0d\ {\x0d\ return a/b;\ x0d\ }\x0d\\x0d\private void comboBox1_SelectedIndexChanged(remitente del objeto, System.EventArgs e)\x0d\ {\x0d\\x0d\ }\x0d\\x0d\ private void textBox1_TextChanged(remitente del objeto, System.EventArgs e) \x0d\ {\x0d\\x0d\ }\x0d\\x0d\ botón de anulación privado1_Click(remitente del objeto, 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\ botón de anulación privado2_Click(remitente del objeto, System.EventArgs e)\x0d\ {\x0d\ this.textBox1.Text=null;\x0d \ this.textBox2.Text = null; \x0d\ this.textBox3.Text = null \x0d\ }\x0d\\x0d\ botón vacío privado3_Click(remitente del objeto, EventArgs e)\x0d\ {\x0d\ \x0d\ //this.Hide();\x0d\ Application.Exit();\x0d\ //this.Close();\x0d\ \x0d\ }\x0d\ }\x0d\}