먼저 프로젝트 생성 -> CLR 빈 프로젝트를 생성 -> 솔루션 탐색기에서 프로젝트 우클릭 속성 -> 구성속성/링커/고급에 진입점을 main
으로 설정 , 시스템의 하위 시스템을 창 으로 설정
이후 새 항목에서 winform 파일 생성 후 밑의 코드를 입력 후 실행
using namespace System; using namespace System::Windows::Forms; [STAThreadAttribute] void main(array<String^>^ args) { Application::SetCompatibleTextRenderingDefault(false); Application::EnableVisualStyles(); Project1::MyForm form; // Project1 - 본인 프로젝트 이름 Application::Run(% form); }
string sb = "hello"; cout << sb; label1->Text = gcnew String(sb.c_str()); // str::string를 system 으로
label1->Text = gcnew String(to_string(cl.Add(5, 15)).c_str());
#include <msclr\marshal_cppstd.h> 헤더를 추가해주고,
string message = msclr::interop::marshal_as<std::string>(textBox1->Text); // system::str을 std::str로 label2->Text = textBox1->Text;
MyForm2 f2; f2.ShowDialog();
MyForm2의 경우 새로운 form 헤더를 생성 후 #include
를 하여 객체화 시켜준다.
System::Windows::Forms::Label^ the_label1; the_label1 = (gcnew System::Windows::Forms::Label()); the_label1->Text = L"메시지"; the_label1->AutoSize = true; tableLayoutPanel1->Controls->Add(the_label1, 0, 0);
초기 생성자 코드에 작성 시 디자인 폼 수정 시 오류가 발생할 수 있다.
void InitializeComponent(void) 함수 안에 this->Load += gcnew System::EventHandler(this, &resourceDetail::MyForm_Load);
코드 작성 후
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
함수로 이벤트 작성하기