티스토리 뷰

프로그래밍/관리C++

폼에 컨트롤 추가

에어버스 2018. 4. 8. 15:14

버튼 추가

폼에 버튼 추가하려면 버튼의 위치(Point)와 크기(Size)를 설정하기 위해 System::Drawing 이 필요해서 3, 8행을 추가한다.

CppForm 클래스의 생성자에서 버튼을 만들고 속성(텍스트, 크기, 위치)을 지정하는 Setup_Buttons() 을 만든다.

20, 21행의 Controls 속성은 현재 폼에 추가된 모든 컨트롤들에 대한 참조를 가지므로, 버튼을 추가해줘야 화면에서 보여진다.

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
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
 
using namespace System;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Drawing;
 
public ref class CppForm : public Form 
{
private:
    Button ^ btn1, ^btn2;
 
public:
    CppForm()
    {
        Text = "Test Form";
        Setup_Buttons();
        Controls->Add(btn1);
        Controls->Add(btn2);
        //FormBorderStyle = ButtonBorderStyle::Fixed3D;
    };
    void Setup_Buttons()
    {
        btn1 = gcnew Button();
        btn1->Text = "OK";
        btn1->Size = System::Drawing::Size(7025);
        btn1->Location = Point(130225);
 
        btn2 = gcnew Button();
        btn2->Text = "Cancel";
        btn2->Size = System::Drawing::Size(7025);
        btn2->Location = Point(210225);
    }
};
 
int main(array<System::String ^> ^args)
{
    Application::Run(gcnew CppForm());
    return 0;
}
cs

실행결과>

이외 코드는 http://petra.tistory.com/1179 참조.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
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