Winforms 无法在单击form2的按钮时访问Form1

Winforms 无法在单击form2的按钮时访问Form1,winforms,visual-c++,Winforms,Visual C++,我的应用程序在windows窗体应用程序vc++中有两个窗体。我的第一个表格是Form1.h,第二个表格是form2.h。我想做的是点击Form1.h上的按钮1调用form2。对于从Form1调用form2,我使用了以下代码 #include “Form1.h” ...... private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { form2^ f

我的应用程序在windows窗体应用程序vc++中有两个窗体。我的第一个表格是Form1.h,第二个表格是form2.h。我想做的是点击Form1.h上的按钮1调用form2。对于从Form1调用form2,我使用了以下代码

#include “Form1.h”
......
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 form2^ fm=gcnew form2;
                 fm->Visible=true;
                 this->Visible=false;
             }
这很好用。但我无法通过点击form2上的按钮调用Form1。一旦我将Form1.h包含在form2.h文件中,它就会给出以下错误:-

>d:\vs\testformapp\testformapp\Form1.h(81): error C2065: 'form2' : undeclared identifier
1>d:\vs\testformapp\testformapp\Form1.h(81): error C2065: 'fm' : undeclared identifier
1>d:\vs\testformapp\testformapp\Form1.h(81): error C2061: syntax error : identifier 'form2'
1>d:\vs\testformapp\testformapp\Form1.h(82): error C2065: 'fm' : undeclared identifier
1>d:\vs\testformapp\testformapp\Form1.h(82): error C2227: left of '->Visible' must point to class/struct/union/generic type
我只想要Form1->Visible=true;在窗体2的按钮上单击。我不想在点击form2的按钮时初始化Form1,因为它将初始化Form1的所有参数,而我的应用程序要求不是这样

谁能告诉我这个问题的解决办法吗。
任何帮助都将不胜感激。

您需要将此方法移到.cpp文件中,以便正确地包含表单.h文件。避免在C++/CLI Winforms应用程序上花费太多时间,VS2012不再支持这些应用程序。