계산기, 닷넷 C# 윈폼기반의 계산기를 작성하세요
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.btnC = new System.Windows.Forms.Button();
this.btnCE = new System.Windows.Forms.Button();
this.btnback = new System.Windows.Forms.Button();
this.btnminus = new System.Windows.Forms.Button();
this.btnplus = new System.Windows.Forms.Button();
this.btnthree = new System.Windows.Forms.Button();
this.btntwo = new System.Windows.Forms.Button();
this.btnone = new System.Windows.Forms.Button();
this.btndivide = new System.Windows.Forms.Button();
this.btnnine = new System.Windows.Forms.Button();
this.btneight = new System.Windows.Forms.Button();
this.btnseven = new System.Windows.Forms.Button();
this.btnmultiply = new System.Windows.Forms.Button();
this.btnsix = new System.Windows.Forms.Button();
this.btfive = new System.Windows.Forms.Button();
this.btnfour = new System.Windows.Forms.Button();
this.btnzero = new System.Windows.Forms.Button();
this.btnequal = new System.Windows.Forms.Button();
this.btnperiod = new System.Windows.Forms.Button();
this.btnroot = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(26, 17);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(286, 21);
this.textBox1.TabIndex = 0;
//
// btnC
//
this.btnC.Location = new System.Drawing.Point(28, 62);
this.btnC.Name = "btnC";
this.btnC.Size = new System.Drawing.Size(57, 37);
this.btnC.TabIndex = 1;
this.btnC.Text = "C";
this.btnC.UseVisualStyleBackColor = true;
this.btnC.Click += new System.EventHandler(this.btnC_Click_1);
//
// btnCE
//
this.btnCE.Location = new System.Drawing.Point(104, 62);
this.btnCE.Name = "btnCE";
this.btnCE.Size = new System.Drawing.Size(57, 37);
this.btnCE.TabIndex = 2;
this.btnCE.Text = "CE";
this.btnCE.UseVisualStyleBackColor = true;
this.btnCE.Click += new System.EventHandler(this.btnCE_Click);
//
// btnback
//
this.btnback.Location = new System.Drawing.Point(178, 62);
this.btnback.Name = "btnback";
this.btnback.Size = new System.Drawing.Size(57, 37);
this.btnback.TabIndex = 3;
this.btnback.Text = "<--";
this.btnback.UseVisualStyleBackColor = true;
this.btnback.Click += new System.EventHandler(this.btnback_Click);
//
// btnminus
//
this.btnminus.Location = new System.Drawing.Point(257, 62);
this.btnminus.Name = "btnminus";
this.btnminus.Size = new System.Drawing.Size(57, 37);
this.btnminus.TabIndex = 4;
this.btnminus.Text = "-";
this.btnminus.UseVisualStyleBackColor = true;
this.btnminus.Click += new System.EventHandler(this.btnminus_Click);
//
// btnplus
//
this.btnplus.Location = new System.Drawing.Point(257, 115);
this.btnplus.Name = "btnplus";
this.btnplus.Size = new System.Drawing.Size(57, 37);
this.btnplus.TabIndex = 8;
this.btnplus.Text = "+";
this.btnplus.UseVisualStyleBackColor = true;
this.btnplus.Click += new System.EventHandler(this.btnplus_Click);
//
// btnthree
//
this.btnthree.Location = new System.Drawing.Point(178, 115);
this.btnthree.Name = "btnthree";
this.btnthree.Size = new System.Drawing.Size(57, 37);
this.btnthree.TabIndex = 7;
this.btnthree.Text = "3";
this.btnthree.UseVisualStyleBackColor = true;
this.btnthree.Click += new System.EventHandler(this.btnthree_Click);
//
// btntwo
//
this.btntwo.Location = new System.Drawing.Point(104, 115);
this.btntwo.Name = "btntwo";
this.btntwo.Size = new System.Drawing.Size(57, 37);
this.btntwo.TabIndex = 6;
this.btntwo.Text = "2";
this.btntwo.UseVisualStyleBackColor = true;
this.btntwo.Click += new System.EventHandler(this.bttntwo_Click);
//
// btnone
//
this.btnone.Location = new System.Drawing.Point(28, 115);
this.btnone.Name = "btnone";
this.btnone.Size = new System.Drawing.Size(57, 37);
this.btnone.TabIndex = 5;
this.btnone.Text = "1";
this.btnone.UseVisualStyleBackColor = true;
this.btnone.Click += new System.EventHandler(this.btnone_Click);
//
// btndivide
//
this.btndivide.Location = new System.Drawing.Point(257, 218);
this.btndivide.Name = "btndivide";
this.btndivide.Size = new System.Drawing.Size(57, 37);
this.btndivide.TabIndex = 16;
this.btndivide.Text = "/";
this.btndivide.UseVisualStyleBackColor = true;
this.btndivide.Click += new System.EventHandler(this.btndivide_Click);
//
// btnnine
//
this.btnnine.Location = new System.Drawing.Point(178, 218);
this.btnnine.Name = "btnnine";
this.btnnine.Size = new System.Drawing.Size(57, 37);
this.btnnine.TabIndex = 15;
this.btnnine.Text = "9";
this.btnnine.UseVisualStyleBackColor = true;
this.btnnine.Click += new System.EventHandler(this.btnnine_Click);
//
// btneight
//
this.btneight.Location = new System.Drawing.Point(104, 218);
this.btneight.Name = "btneight";
this.btneight.Size = new System.Drawing.Size(57, 37);
this.btneight.TabIndex = 14;
this.btneight.Text = "8";
this.btneight.UseVisualStyleBackColor = true;
this.btneight.Click += new System.EventHandler(this.btneight_Click);
//
// btnseven
//
this.btnseven.Location = new System.Drawing.Point(28, 218);
this.btnseven.Name = "btnseven";
this.btnseven.Size = new System.Drawing.Size(57, 37);
this.btnseven.TabIndex = 13;
this.btnseven.Text = "7";
this.btnseven.UseVisualStyleBackColor = true;
this.btnseven.Click += new System.EventHandler(this.btnseven_Click);
//
// btnmultiply
//
this.btnmultiply.Location = new System.Drawing.Point(257, 165);
this.btnmultiply.Name = "btnmultiply";
this.btnmultiply.Size = new System.Drawing.Size(57, 37);
this.btnmultiply.TabIndex = 12;
this.btnmultiply.Text = "*";
this.btnmultiply.UseVisualStyleBackColor = true;
this.btnmultiply.Click += new System.EventHandler(this.btnmultiply_Click);
//
// btnsix
//
this.btnsix.Location = new System.Drawing.Point(178, 165);
this.btnsix.Name = "btnsix";
this.btnsix.Size = new System.Drawing.Size(57, 37);
this.btnsix.TabIndex = 11;
this.btnsix.Text = "6";
this.btnsix.UseVisualStyleBackColor = true;
this.btnsix.Click += new System.EventHandler(this.btnsix_Click);
//
// btfive
//
this.btfive.Location = new System.Drawing.Point(104, 165);
this.btfive.Name = "btfive";
this.btfive.Size = new System.Drawing.Size(57, 37);
this.btfive.TabIndex = 10;
this.btfive.Text = "5";
this.btfive.UseVisualStyleBackColor = true;
this.btfive.Click += new System.EventHandler(this.btnfive_Click);
//
// btnfour
//
this.btnfour.Location = new System.Drawing.Point(28, 165);
this.btnfour.Name = "btnfour";
this.btnfour.Size = new System.Drawing.Size(57, 37);
this.btnfour.TabIndex = 9;
this.btnfour.Text = "4";
this.btnfour.UseVisualStyleBackColor = true;
this.btnfour.Click += new System.EventHandler(this.btnfour_Click);
//
// btnzero
//
this.btnzero.Location = new System.Drawing.Point(28, 271);
this.btnzero.Name = "btnzero";
this.btnzero.Size = new System.Drawing.Size(57, 37);
this.btnzero.TabIndex = 17;
this.btnzero.Text = "0";
this.btnzero.UseVisualStyleBackColor = true;
this.btnzero.Click += new System.EventHandler(this.btnzero_Click);
//
// btnequal
//
this.btnequal.Location = new System.Drawing.Point(178, 271);
this.btnequal.Name = "btnequal";
this.btnequal.Size = new System.Drawing.Size(57, 37);
this.btnequal.TabIndex = 19;
this.btnequal.Text = "=";
this.btnequal.UseVisualStyleBackColor = true;
this.btnequal.Click += new System.EventHandler(this.btnequal_Click);
//
// btnperiod
//
this.btnperiod.Location = new System.Drawing.Point(104, 271);
this.btnperiod.Name = "btnperiod";
this.btnperiod.Size = new System.Drawing.Size(57, 37);
this.btnperiod.TabIndex = 18;
this.btnperiod.Text = ".";
this.btnperiod.UseVisualStyleBackColor = true;
this.btnperiod.Click += new System.EventHandler(this.btnperiod_Click);
//
// btnroot
//
this.btnroot.Location = new System.Drawing.Point(255, 271);
this.btnroot.Name = "btnroot";
this.btnroot.Size = new System.Drawing.Size(57, 37);
this.btnroot.TabIndex = 20;
this.btnroot.Text = "√";
this.btnroot.UseVisualStyleBackColor = true;
this.btnroot.Click += new System.EventHandler(this.btnroot_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(333, 335);
this.Controls.Add(this.btnroot);
this.Controls.Add(this.btnequal);
this.Controls.Add(this.btnperiod);
this.Controls.Add(this.btnzero);
this.Controls.Add(this.btndivide);
this.Controls.Add(this.btnnine);
this.Controls.Add(this.btneight);
this.Controls.Add(this.btnseven);
this.Controls.Add(this.btnmultiply);
this.Controls.Add(this.btnsix);
this.Controls.Add(this.btfive);
this.Controls.Add(this.btnfour);
this.Controls.Add(this.btnplus);
this.Controls.Add(this.btnthree);
this.Controls.Add(this.btntwo);
this.Controls.Add(this.btnone);
this.Controls.Add(this.btnminus);
this.Controls.Add(this.btnback);
this.Controls.Add(this.btnCE);
this.Controls.Add(this.btnC);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "미니계산기";
this.ResumeLayout(false);
this.PerformLayout();
private System.Windows.Forms.Button btnC;
private System.Windows.Forms.Button btnCE;
private System.Windows.Forms.Button btnback;
private System.Windows.Forms.Button btnminus;
private System.Windows.Forms.Button btnplus;
private System.Windows.Forms.Button btnthree;
private System.Windows.Forms.Button btntwo;
private System.Windows.Forms.Button btnone;
private System.Windows.Forms.Button btndivide;
private System.Windows.Forms.Button btnnine;
private System.Windows.Forms.Button btneight;
private System.Windows.Forms.Button btnseven;
private System.Windows.Forms.Button btnmultiply;
private System.Windows.Forms.Button btnsix;
private System.Windows.Forms.Button btfive;
private System.Windows.Forms.Button btnfour;
private System.Windows.Forms.Button btnzero;
private System.Windows.Forms.Button btnequal;
private System.Windows.Forms.Button btnperiod;
private System.Windows.Forms.Button btnroot;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int count;
{
textBox1.Clear();
count = 0;
}
{
{
num1 = 0; textBox1.Clear();
}
else if (num1 > 0 && textBox1.TextLength > 0)
{
textBox1.Clear();
}
{
string text = textBox1.Text;
textBox1.Clear();
for (int i = 0; i < lenght; i++)
textBox1.Text = textBox1.Text + text[i];
{
if (textBox1.Text != "")
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
}
}
{
textBox1.Text = textBox1.Text + 1;
}
{
textBox1.Text = textBox1.Text + 2;
}
{
textBox1.Text = textBox1.Text + 3;
}
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
}
{
textBox1.Text = textBox1.Text + 4;
}
{
textBox1.Text = textBox1.Text + 5;
}
{
textBox1.Text = textBox1.Text + 6;
}
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
}
{
textBox1.Text = textBox1.Text + 7;
}
{
textBox1.Text = textBox1.Text + 8;
}
{
textBox1.Text = textBox1.Text + 9;
}
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 4;
}
{
textBox1.Text = textBox1.Text + 0;
}
{
int c = textBox1.TextLength;
int flag = 0;
string text = textBox1.Text;
for (int i = 0; i < c; i++)
{
if (text[i].ToString() == ".")
{
flag = 1; break;
}
else
{
flag = 0;
}
}
if (flag == 0)
{
textBox1.Text = textBox1.Text + ".";
}
}
{
compute(count);
}
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 5;
}
{
switch (count)
{
case 1:
ans = num1 - float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
ans = num1 / float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 5:
ans = (float)Math.Sqrt(num1);
textBox1.Text = ans.ToString();
break;
default:
break;
}
}
}
}