我创建了两种形式,即主页和数据页,我需要使用按钮切换到表单。从主页我使用以下代码导航到datapage:
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();
}
但是我不断收到错误“对象引用未设置为对象的实例”。请帮帮我。谢谢
附:我是Visual C ++的新手
好吧那是因为你从未初始化你的home变量,你只是声明它然后使用它,让其他页面公共分配在你的第一个代码片段中作为page->otherpage = this;
然后使用otherpage到otherpage->show()