GroupBox내에 있는 라디오 버튼의 체크된 값(Tag)을 가지고 온다.
매번 가져오기 귀찮아서 ㅡ_ㅡ;
namespace WindowsFormsApplication1 { public partial class Form3 : Form { public Form3() { InitializeComponent(); this.groupBox1.SetRadioBoxValue("0001"); //값 세팅 } private void button1_Click(object sender, EventArgs e) { var q= this.groupBox1.GetRadioBoxValue(); //체크된 박스의 tag값 읽어오기 this.c1TextBox1.Text = q.ToString(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public static class ControlExtention { /// <summary> /// Tag로 세팅된 값을 읽어온다. /// </summary> /// <param name="groupBox">The group box.</param> /// <returns></returns> public static object GetRadioBoxValue(this GroupBox groupBox) { try { foreach (Control item in groupBox.Controls) { if (item.GetType() == typeof(RadioButton)) { if (((RadioButton)item).Checked) { return item.Tag.ToString(); } } } return string.Empty; } catch { return string.Empty; } } /// <summary> /// Tag로 세팅된 저장한다. /// </summary> /// <param name="groupBox">The group box.</param> /// <returns></returns> public static void SetRadioBoxValue(this GroupBox groupBox , string tagValue) { foreach (Control item in groupBox.Controls) { if (item.GetType() == typeof(RadioButton)) { if (((RadioButton)item).Tag.ToString() == tagValue ) { ((RadioButton)item).Checked = true; return; } } } }//End For } }
확장메서드
'C#.NET' 카테고리의 다른 글
Json.NET c#에서 Json 파싱하기 (0) | 2019.07.18 |
---|---|
RTF 포멧을 HTML 포멧으로 변경하기 (0) | 2016.08.23 |
RicherTextBox 를 이용한 이미지 저장 및 포멧 저장 (0) | 2016.08.20 |
IIS 32비트 허용 (0) | 2013.08.22 |
Enum 데이터바인딩 및 가져오기 (0) | 2013.05.14 |
[ Assembly ,어셈블리 ] 클래스 이름으로 동적으로 컨트롤 생성하기 (1) | 2013.03.08 |
개체의 선입선출(FIFO) / LIFO(후입선출) (0) | 2012.06.27 |
[ GMap.NET ] c# 에서 구글맵,빙맵등을 을 빠르고 간편하게 개발 (1) | 2012.03.13 |
[ dynamic , ExpandoObject ] C# Class Properties 추가하기 (0) | 2012.01.02 |
[ReportViewer,리포트뷰어] 한페이지에 하나씩보여주기 (0) | 2011.10.11 |