본문 바로가기

C#

C#- Winform 윈폼 기초 문법에 대해 같이 알아 봅시다.

반응형

디자이너 !

namespace WindowsFormsApp1
{
    partial class leejoonho
    {
        /// <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.Btn1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.apple = new System.Windows.Forms.RadioButton();
            this.pear = new System.Windows.Forms.RadioButton();
            this.strawberry = new System.Windows.Forms.RadioButton();
            this.orange = new System.Windows.Forms.RadioButton();
            this.banana = new System.Windows.Forms.RadioButton();
            this.SuspendLayout();
            // 
            // Btn1
            // 
            this.Btn1.Location = new System.Drawing.Point(490, 124);
            this.Btn1.Name = "Btn1";
            this.Btn1.Size = new System.Drawing.Size(234, 191);
            this.Btn1.TabIndex = 0;
            this.Btn1.Text = "눌러";
            this.Btn1.UseVisualStyleBackColor = true;
            this.Btn1.Click += new System.EventHandler(this.Btn1_Click);

            this.Btn1.MouseLeave += new System.EventHandler(this.Btn1_MouseLeave);
            this.Btn1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Btn1_MouseMove);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(110, 29);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(272, 15);
            this.label1.TabIndex = 2;
            this.label1.Text = "질문: 좋아하는 과일을 모두 선택하세요";
            // 
            // apple
            // 
            this.apple.AutoSize = true;
            this.apple.Location = new System.Drawing.Point(67, 99);
            this.apple.Name = "apple";
            this.apple.Size = new System.Drawing.Size(58, 19);
            this.apple.TabIndex = 3;
            this.apple.TabStop = true;
            this.apple.Text = "사과";
            this.apple.UseVisualStyleBackColor = true;
        
            // 
            // pear
            // 
            this.pear.AutoSize = true;
            this.pear.Location = new System.Drawing.Point(67, 137);
            this.pear.Name = "pear";
            this.pear.Size = new System.Drawing.Size(43, 19);
            this.pear.TabIndex = 3;
            this.pear.TabStop = true;
            this.pear.Text = "배";
            this.pear.UseVisualStyleBackColor = true;
            // 
            // strawberry
            // 
            this.strawberry.AutoSize = true;
            this.strawberry.Location = new System.Drawing.Point(67, 173);
            this.strawberry.Name = "strawberry";
            this.strawberry.Size = new System.Drawing.Size(58, 19);
            this.strawberry.TabIndex = 3;
            this.strawberry.TabStop = true;
            this.strawberry.Text = "딸기";
            this.strawberry.UseVisualStyleBackColor = true;
            // 
            // orange
            // 
            this.orange.AutoSize = true;
            this.orange.Location = new System.Drawing.Point(67, 246);
            this.orange.Name = "orange";
            this.orange.Size = new System.Drawing.Size(73, 19);
            this.orange.TabIndex = 3;
            this.orange.TabStop = true;
            this.orange.Text = "오렌지";
            this.orange.UseVisualStyleBackColor = true;
            // 
            // banana
            // 
            this.banana.AutoSize = true;
            this.banana.Location = new System.Drawing.Point(67, 212);
            this.banana.Name = "banana";
            this.banana.Size = new System.Drawing.Size(73, 19);
            this.banana.TabIndex = 3;
            this.banana.TabStop = true;
            this.banana.Text = "바나나";
            this.banana.UseVisualStyleBackColor = true;
            // 
            // leejoonho
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(723, 314);
            this.Controls.Add(this.banana);
            this.Controls.Add(this.orange);
            this.Controls.Add(this.strawberry);
            this.Controls.Add(this.pear);
            this.Controls.Add(this.apple);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.Btn1);
            this.Name = "leejoonho";
            this.Text = "이준호";
 
            this.DoubleClick += new System.EventHandler(this.leejoonho_DoubleClick);
            this.MouseLeave += new System.EventHandler(this.leejoonho_MouseLeave);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.leejoonho_MouseMove);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button Btn1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.RadioButton apple;
        private System.Windows.Forms.RadioButton pear;
        private System.Windows.Forms.RadioButton strawberry;
        private System.Windows.Forms.RadioButton orange;
        private System.Windows.Forms.RadioButton banana;
    }
}

 

 

 

 

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class leejoonho : Form
    {
        bool bButton = false;

        public leejoonho()
        {
            InitializeComponent();
        }

        private void leejoonho_DoubleClick(object sender, EventArgs e)
        {
            if (bButton == false)
            {
                Btn1.Text = "더블 클릭 당함";
                bButton = true;
            }
            else
            {
                Btn1.Text = "헬로 주키";
                bButton = false;
            }
        }

        private void leejoonho_MouseMove(object sender, MouseEventArgs e)
        {
            Text = "마우스 올라옴";
        }

        private void leejoonho_MouseLeave(object sender, EventArgs e)
        {
            Text = "마우스 떠남";
        }

        private void Btn1_MouseMove(object sender, MouseEventArgs e)
        {
            Btn1.Text = " 마우스 올라옴 ";
        }

        private void Btn1_MouseLeave(object sender, EventArgs e)
        {
            Btn1.Text = " 마우스 떠남 ";
        }

        private void Txb1_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void Btn1_Click(object sender, EventArgs e)
        {
            string radiostatus = "";
            RadioButton[] radioButtons = { apple, pear, strawberry, banana };
            foreach (var item in radioButtons)
            {
                //radiostatus = radiostatus + item.Text + " : " + item.Checked + "\n";
                radiostatus = radiostatus + string.Format("{0} :{1}\n ", item.Text, item.Checked);

            }
            MessageBox.Show(radiostatus, "체크박스 상태");
        }

    }
}

 

 

 

강사님은 체크 박스로 하셨지만 난 그냥 라디오 버튼으로 해봤다 안타까운 점이 라디오 버튼은 중복 선택이 불가능하다 .

반응형