본문 바로가기

C#/Button added

폼에 버튼 추가

C#에서 자동으로 생성된 기본 윈도우 프로그램 코드에 Button을 추가할 경우 반영되는 소스코드의 내용

자동 생성된 기본 코드에 버튼을 하나 올려 놓고 실행한 상태


소스코드상의 변화

Form1.cs (이벤트 핸들러 선언 )

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } } }


Form1.Design.cs ( 버튼 생성, 이벤트핸들러 등록, 폼에 버튼 추가 )

namespace WindowsFormsApplication1 { partial class Form1 { /// <summary> /// 필수 디자이너 변수입니다. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 사용 중인 모든 리소스를 정리합니다. /// </summary> /// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form 디자이너에서 생성한 코드 /// <summary> /// 디자이너 지원에 필요한 메서드입니다. /// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(89, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(87, 23); this.button1.TabIndex = 0; this.button1.Text = "버튼 테스트"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; } }