95. 체크박스(CheckBox) / 라디오버튼(RadioButton)
.NET프로그래밍/WinForm 2009. 8. 21. 17:28 |
==> MainForm.cs
#region 컨텍스트메뉴
private void cmsAbout_Click(object sender, EventArgs e)
{
//FrmAbout fa = new FrmAbout();
//fa.ShowDialog();
miAbout_Click(null, null); // 재 사용
}
private void cmsExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion
private void miLable_Click(object sender, EventArgs e)
{
MyWinForms.Controls.FrmButtonLableTextBox blt = new MyWinForms.Controls.FrmButtonLableTextBox();
blt.MdiParent = this;
blt.Show();
}
private void miCheckBoxRadioButton_Click(object sender, EventArgs e)
{
MyWinForms.Controls.FrmCheckBoxRadioButton cbrb = new MyWinForms.Controls.FrmCheckBoxRadioButton();
cbrb.MdiParent = this;
cbrb.Show();
}
==============================================================================================
==> FrmCheckBoxRadioButton.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 MyWinForms.Controls
{
public partial class FrmCheckBoxRadioButton : Form
{
public FrmCheckBoxRadioButton()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
string msg = "";
// 관심사항
if (this.chkSeeSharp.Checked) //[1] 체크되었다면
{
msg += this.chkSeeSharp.Text + "\r\n";
}
if (this.chkAspNet.Checked == true) //[2] 체크 true면
{
msg += this.chkAspNet.Text + "\r\n";
}
if (!chkSilverlight.Checked) //[3] 체크가 되지 않았다면,
{
// Empty
}
else
{
msg += this.chkSilverlight.Text + "\r\n";
}
// 성별
if (this.rdoMan.Checked)
{
msg += String.Format("{0}{1}{0}", "\r\n", rdoMan.Text);
}
else
{
msg += String.Format("{0}{1}{0}", "\r\n", optWomen.Text);
}
this.txtResult.Text = msg;
}
private void FrmCheckBoxRadioButton_Load(object sender, EventArgs e)
{
// 폼 로드시 동적으로 라디오버튼 체크
this.rdoMan.Checked = true;
}
}
}
< 실행결과 >
==> 체크박스에 체크하고 라디오버튼에서 선택한 후 "확인"버튼을 누르면 아래 텍스트박스에서 체크한 결과가 출력됨.(여기서는 초기에 FrmCheckBoxRadioButton.cs[디자인]에서 "ASP.NET"체크박스의 속성을 Checked --> True로 해주었고, FrmCheckBoxRadioButton.cs코드에서 this.rdoMan.Checked = true;로 하여 폼 로드시 동적으로 "남자"라디오버튼이 체크되게 하였다.)
체크박스는 다중선택이 가능하지만 라디오버튼은 택1만 가능하다.
'.NET프로그래밍 > WinForm' 카테고리의 다른 글
97. 링크레이블(LinkLabel) (0) | 2009.08.24 |
---|---|
96. 마스크(Mask) / 리치(Rich) / 읽기전용(ReadOnly) 텍스트박스(TextBox) (0) | 2009.08.24 |
94. 버튼 / 레이블 / 텍스트박스 (Button / Label / TextBox) (0) | 2009.08.21 |
(테스트) 인터넷쇼핑몰 - WinForm을 이용하여 회원으로부터 회원번호, 주문상품코드, 주문수량을 입력받아 결과를 출력하는 프로그램 (0) | 2009.08.21 |
93. WinForm을 이용한 체중 관리 프로그램 (0) | 2009.08.20 |