본문 바로가기

   
Programming/Winform

체크박스, 컨트롤

반응형
체크박스는 배열에 넣을때 일일이 넣어줘야 한다.



 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 WindowsForms01

{

       public partial class CheckBox01 : Form

       {

             //체크박스 배열

             List<CheckBox> list;

 

             public CheckBox01()

             {

                    InitializeComponent();

                    list = new List<CheckBox>();

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    //체크 박스의 체크 확인

                    MessageBox.Show(checkBox1.Checked.ToString());

                    MessageBox.Show(checkBox2.Checked.ToString());

                    MessageBox.Show(checkBox3.Checked.ToString());

             }

 

             private void button2_Click(object sender, EventArgs e)

             {

                    for (int i = 0; i < list.Count; i++)

                    {

                           MessageBox.Show(list[i].Text + " : " + list[i].Checked.ToString());

                    }

             }

 

             private void CheckBox01_Load(object sender, EventArgs e)

             {

                    //초기화

                    list.Add(this.checkBox1);

                    list.Add(this.checkBox2);

                    list.Add(this.checkBox3);

 

             }

 

             private void button3_Click(object sender, EventArgs e)

             {

                    for (int i = 0; i < this.groupBox1.Controls.Count; i++)

                    {

                           MessageBox.Show(((CheckBox)this.groupBox1.Controls[i]).Checked.ToString()

                                 + " : " +

                                 ((CheckBox)this.groupBox1.Controls[i]).Text);

                    }

             }

       }

}

 



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 WindowsForms01

{

       public partial class CheckBox02 : Form

       {

             public CheckBox02()

             {

                    InitializeComponent();

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    if (checkBox1.Checked)

                           MessageBox.Show("접수됨");

                    else

                           MessageBox.Show("취소처리");

             }

 

             private void checkBox2_CheckedChanged(object sender, EventArgs e)

             {

                    //this.label1.Text = checkBox2.Checked.ToString();

                    if (checkBox2.Checked)

                           this.label1.Text = "통과";

                    else

                           this.label1.Text = "거절";

             }

 

             private void checkBox3_CheckedChanged(object sender, EventArgs e)

             {

                    if (checkBox3.Checked)

                    {

                           this.Size = new Size(300, 300);

                    }

                    else

                    {

                           this.Size = new Size(300, 150);

                    }

             }

       }

}

 

 




 

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 WindowsForms01

{

       public partial class CheckBox03 : Form

       {

             public CheckBox03()

             {

                    InitializeComponent();

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    //MessageBox.Show(checkBox1.Checked.ToString());

                    MessageBox.Show(checkBox1.CheckState.ToString());

             }

       }

}

 

 


 

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 WindowsForms01

{

       public partial class Radio01 : Form

       {

             public Radio01()

             {

                    InitializeComponent();

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    MessageBox.Show(radioButton1.Checked.ToString());

                    MessageBox.Show(radioButton2.Checked.ToString());

 

                    if (radioButton1.Checked)

                           MessageBox.Show("남탕으로~");

                    else if (radioButton2.Checked)

                           MessageBox.Show("여탕으로~");

                    else

                           MessageBox.Show("못들어옴~");

             }

 

             private void Radio01_Load(object sender, EventArgs e)

             {

                    //초기화 : 성년, 여자 기본

                    radioButton6.Checked = true;

                    radioButton7.Checked = true;

             }

 

             private void radioButton4_CheckedChanged(object sender, EventArgs e)

             {

                    if (radioButton4.Checked)

                    {

                           this.BackColor = Color.White;

                    }

             }

 

             private void radioButton5_CheckedChanged(object sender, EventArgs e)

             {

                    if (radioButton5.Checked)

                    {

                           this.BackColor = Color.Black;

                    }

 

             }

 

       }

}

 

 

반응형