사용 Tool : MiscroSoft Visual Studio 2003
사용 언어 : C#
개 요 : 무지 간단한 곱셈 계산기..설명이 필요하냐??
결과 부분은 속성의 ReadOnly Property 를 True 로 변환하면 읽기전용이 된다.
[ Source ]
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace lovelydai_ex2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox numBox_1;
private System.Windows.Forms.TextBox numBox_2;
private System.Windows.Forms.TextBox answer;
private System.Windows.Forms.Button Submit;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.numBox_1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.numBox_2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.answer = new System.Windows.Forms.TextBox();
this.Submit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// numBox_1
//
this.numBox_1.AutoSize = false;
this.numBox_1.Location = new System.Drawing.Point(16, 24);
this.numBox_1.Name = "numBox_1";
this.numBox_1.Size = new System.Drawing.Size(88, 32);
this.numBox_1.TabIndex = 0;
this.numBox_1.Text = "";
//
// label1
//
this.label1.Font = new System.Drawing.Font("DotumChe", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.label1.Location = new System.Drawing.Point(112, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 32);
this.label1.TabIndex = 1;
this.label1.Text = "곱하기";
//
// numBox_2
//
this.numBox_2.AutoSize = false;
this.numBox_2.Location = new System.Drawing.Point(176, 24);
this.numBox_2.Name = "numBox_2";
this.numBox_2.Size = new System.Drawing.Size(88, 32);
this.numBox_2.TabIndex = 2;
this.numBox_2.Text = "";
//
// label2
//
this.label2.Font = new System.Drawing.Font("DotumChe", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.label2.Location = new System.Drawing.Point(272, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 32);
this.label2.TabIndex = 3;
this.label2.Text = "는?";
//
// answer
//
this.answer.AutoSize = false;
this.answer.Location = new System.Drawing.Point(328, 24);
this.answer.Name = "answer";
this.answer.ReadOnly = true;
this.answer.Size = new System.Drawing.Size(88, 32);
this.answer.TabIndex = 4;
this.answer.Text = "";
//
// Submit
//
this.Submit.Location = new System.Drawing.Point(40, 88);
this.Submit.Name = "Submit";
this.Submit.Size = new System.Drawing.Size(352, 32);
this.Submit.TabIndex = 5;
this.Submit.Text = "결 과 보 기";
this.Submit.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 157);
this.Controls.Add(this.Submit);
this.Controls.Add(this.answer);
this.Controls.Add(this.label2);
this.Controls.Add(this.numBox_2);
this.Controls.Add(this.label1);
this.Controls.Add(this.numBox_1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
answer.Text = Convert.ToString(Convert.ToInt16(numBox_1.Text) * Convert.ToInt16(numBox_2.Text));
}
// Convert Object 에 여러가지 변환 Method 가 존재하는데..
// ToString 은 문자열로 변환, ToInt16 은 16bit 정수형으로 변환하여 준다.
// 입력한 숫자는 문자열 이므로 각각 ToInt16 method 로 숫자형으로 변환하여 준 후..
// 결과값을 Textbox 에 찍기 위해서는 기본적으로 문자열을 사용해야 하므로..
// 문자열로 변환하여 준다.
}
}
댓글
댓글 쓰기