我在Visual Studio 2010中使用C ++创建了Windows窗体应用程序。我创建了两个窗体(Form1,Form2)。我在Form1上添加了按钮。现在我想点击按钮转到Form2(隐藏Form1)。
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
这样做的正确方法是什么?
我试过这个:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2->ShowDialog();
}
但是这在构建时给了我这个错误:
error C2065: 'Form2' : undeclared identifier
error C2227: left of '->ShowDialog' must point to class/struct/union/generic type
1> type is ''unknown-type''
答案 0 :(得分:0)
我忘了加入" Form1.h":
#include "Form2.h"
然后在Form1.h中:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2 ^ form2 = gcnew Form2;
form2->Show();
}