如何返回到以前的窗体C ++ / CLI Windows窗体

时间:2019-02-25 21:36:49

标签: winforms visual-c++ c++-cli

我已经创建了两个表格,即主页和数据页,我需要使用按钮切换到表格。在主页上,我使用以下代码导航到数据页:

DataPage^ page = gcnew DataPage();
page->ShowDialog();
this->Hide();

在数据页面中,单击“主页”按钮后,我需要返回主页。我尝试使用以下代码来实现它:

public ref class DataPage: public System::Windows::Forms::Form
{
private: System::Windows::Forms::Form^ otherPage;


public: 
    DataPage(void)
    {
    HomePage: System::Windows::Forms::Form ^ home;
        otherPage = home;
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

    private: System::Void btn_home_Click(System::Object^  sender, 
    System::EventArgs^  e) {
    this->Hide();
    otherPage->Show();
    }

但是,我不断收到错误消息“对象引用未设置为对象的实例”。请帮我。谢谢

p.s。我是Visual C ++的新手

1 个答案:

答案 0 :(得分:0)

好吧,因为您从未初始化过home变量,只是声明了它然后使用了它,将 otherpage公开在您的第一个代码段中将其分配为page->otherpage = this;,然后使用otherpage来{ {1}}