我无法从 form2 返回到 form1。
我正在尝试做什么:
单击按钮时,form1会将您带到form2,并且
单击按钮时,form2 将带您到 form1。
我尝试将两种表单上的
this->Visible = false;
更改为 this->Close();
,但出现此错误
1>c:\users\form2.h(172): error C2065: 'form1' : undeclared identifier
1>c:\users\form2.h(172): error C2065: 'go_form1' : undeclared identifier
1>c:\users\form2.h(172): error C2061: syntax error : identifier 'menu_form'
1>c:\users\form2.h(173): error C2065: 'go_form1' : undeclared identifier
1>c:\users\form2.h(173): error C2227: left of '->Show' must point to class/struct/union/generic type
表格1
#include "form2.h"
private: System::Void start_button_Click(System::Object^ sender, System::EventArgs^ e) {
form2^ go_form2 = gcnew form2();
go_form2->Show();
this->Visible = false;
}
表格2
#include "form1.h"
private: System::Void start_button_Click(System::Object^ sender, System::EventArgs^ e) {
form1^ go_form1 = gcnew form1();
go_form1->Show();
this->Visible = false;
}
编辑: 我尝试这样做C++/CLI - 如何打开一个新表单并返回现在它打开第二个表单,但在小窗口中,上面没有任何内容
表格2
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
public:
Form2(System::Windows::Forms::Form ^ form1)
{
otherform = form1;
InitializeComponent();
}
private: System::Windows::Forms::Form ^ otherform;
private: System::Void Button_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
otherform->Show();
}
表格1
private: System::Void button_Click(System::Object^ sender, System::EventArgs^ e) {
Form2^ go_form2 = gcnew Form2(this);
go_form2->Show();
this->Hide();
}
我现在可以工作了。我在我的构造函数中注释掉了
InitializeComponent();
this->Close();
。 form2关闭后,form1打开