0

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

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

我需要帮助的部分是Home Page需要在Setup Info. 要了解我的文件是如何设置的,这是我创建 C++ Windows 窗体应用程序时遵循的 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它似乎并没有杀死我的程序时,我该如何解决这个问题?

4

1 回答 1

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;
}
于 2013-07-19T17:07:39.387 回答