C++ cli 从不同的隐藏表单C+获取信息+/clr

C++ cli 从不同的隐藏表单C+获取信息+/clr,c++-cli,windows-forms-designer,msdn,C++ Cli,Windows Forms Designer,Msdn,我在C++/CLR Visual Studio 2012中创建了一个Windows窗体应用程序 目标是让用户在名为主页的表单中输入值。然后,在填写完所有信息后,他们单击一个按钮,将隐藏主页表单,然后显示名为设置信息的第二个表单 我需要帮助的部分是主页上的信息需要在设置信息中访问。要了解我的文件是如何设置的,这是我创建的我的C++ Windows窗体应用程序的YouTube视频。 在我的主页.h // Button that will hide the Home Page Form and the

我在C++/CLR Visual Studio 2012中创建了一个Windows窗体应用程序

目标是让用户在名为
主页
的表单中输入值。然后,在填写完所有信息后,他们单击一个按钮,将隐藏
主页
表单,然后显示名为
设置信息
的第二个表单

我需要帮助的部分是
主页上的信息
需要在
设置信息
中访问。要了解我的文件是如何设置的,这是我创建的我的C++ Windows窗体应用程序的YouTube视频。

在我的
主页.h

// Button that will hide the Home Page Form and then show the SetupInfo Form.
private: System::Void Start_Click(System::Object^  sender, System::EventArgs^  e) {
                 this->Hide();
                 SetupInfo^ SetupInfo = gcnew ExcelToPPT::SeuUpInfo();
                 SetupInfo->Show();

}
在my
Setup Info.H

// When Setup Info is loaded button1 will have the text of textbox1 from Home Page Form. 
private: System::Void SetupInfo_Load(System::Object^  sender, System::EventArgs^ e) {

    button1->Text = HomePage->Textbox1->Text;
             }
这是一般的想法,但不起作用。我怎样才能让它工作

如果你需要更多的信息,请告诉我

[编辑]

我可以通过外部全局变量来实现这一点,但是否有其他方法可以直接访问文本框


另外,如果我退出我的
设置信息
它似乎不会杀死我的程序,那么我该如何解决这个问题呢?

最简单的方法可能是将您的主页表单传递给新的SetUpInfo表单

private: System::Void Start_Click(System::Object^ sender, System::EventArgs^ e) {
    this->Hide();
    SetUpInfo^ setUpInfo = gcnew ExcelToPPT::SetUpInfo(this);
    setUpInfo->Show();                                 ^^^^
}
在SetUpInfo.h中:

public ref class SetUpInfo : Form
{
private:
    HomePage^ homePage;

public:
    SetUpInfo(HomePage^ homePage);
};
在SetUpInfo.cpp中:

SetUpInfo::SetUpInfo(HomePage^ homePage)
{
    this->homePage = homePage;
}

void SetUpInfo::SetUpInfo_Load(System::Object^  sender, System::EventArgs^ e)
{
    button1->Text = this->homePage->Textbox1->Text;
}

这是一个标准的OOP问题。您需要一个对用户正在查看的主页对象的引用。在“开始”单击方法中很容易找到一个,就是这样。因此,将其传递给SetupInfo构造函数。更好的是,您只需要一个字符串,因此无需传递整个表单类对象并公开其内部。使用接受字符串的构造函数。或者添加可以指定的公共属性。