从不同的隐藏Form C ++ / clr获取信息

时间:2013-07-19 16:31:33

标签: c++-cli windows-forms-designer msdn

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

目标是让用户在名为Home Page的表单中输入值。然后填写所有信息后,他们点击一个按钮,隐藏Home Page表单,然后显示名为Setup Info的第二个表单。

我需要帮助的部分是Home Page中需要访问Setup Info的信息。为了了解我的文件是如何设置的,这是我创建C ++ Windows窗体应用程序Click Here时所遵循的YouTube视频。

在我的HomePage.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();

}

在我的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;
             }

这是一般性的想法,但它不起作用。我如何让它工作?

如果您需要更多信息,请与我们联系。

[编辑]

我可以通过外部全局变量来实现这一点,但还有另一种直接访问文本文本框的方法吗?

同样,我退出我的Setup Information它似乎没有杀死我的程序如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

最简单的方法可能就是将您的主页表单传递给新的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;
}