티스토리 뷰
텍스트, 라디오버튼
컨트롤 등록(http://petra.tistory.com/1180), 이벤트(http://petra.tistory.com/1181) 참조.
GroupBox에 RadioButton 등록하고나서, GroupBox를 컨트롤 등록한다.
클릭한 라디오 버튼의 레이블이 텍스트 상자에 표시된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 |
GroupBox^ gbox; // 컨트롤 변수
RadioButton^ rb1, ^rb2, ^rb3;
TextBox^ text1;
...
// GroupBox
gbox = gcnew GroupBox();
gbox->Text = "언어";
gbox->Location = Point(20, 60);
rb1 = gcnew RadioButton();
rb1->Text = "Visual Basic";
rb1->Location = Point(10, 15);
rb2 = gcnew RadioButton();
rb2->Text = "C#";
rb2->Location = Point(10, 40);
rb3 = gcnew RadioButton();
rb3->Text = "C++";
rb3->Location = Point(10, 65);
rb3->Checked = true;
// TextBox
text1 = gcnew TextBox();
text1->Location = Point(250, 60);
text1->Size = System::Drawing::Size(100, 150);
text1->Multiline = true;
...
gbox->Controls->Add(rb1); // 그룹박스에 라디오버튼 등록
gbox->Controls->Add(rb2);
gbox->Controls->Add(rb3);
Controls->Add(gbox); // 그룹박스 등록
Controls->Add(text1);
//이벤트 등록
rb1->Click += gcnew EventHandler(this, &CppForm::Radio_Clicked);
rb2->Click += gcnew EventHandler(this, &CppForm::Radio_Clicked);
rb3->Click += gcnew EventHandler(this, &CppForm::Radio_Clicked);
...
void Radio_Clicked(Object^ pSender, EventArgs^ pArgs)
{
if (pSender == rb1)
text1->Text = "Visual Basic\r\n";
if (pSender == rb2)
text1->Text = "C#\r\n";
if (pSender == rb3)
text1->Text = "C++\r\n";
}
|
cs |
실행결과>