无法在Visual C ++

时间:2015-10-15 02:55:56

标签: c++ forms

嘿伙计们,我希望有人可以解释为什么我无法在显示和隐藏表单之间切换。

QuizMenu.h 我一直在研究一个简单的测验游戏,在这个游戏中,应用程序通过表格中的一系列问题进行处理!基本上有一个主菜单,用户可以退出应用程序:

    private: System::Void Exit_Click(System::Object^  sender, System::EventArgs^  e) {
    //Exits the application
    QuizMenu::Close();
}

或继续第一个隐藏主菜单并打开Question1表格的问题:

    private: System::Void Enter_Click(System::Object^  sender, System::EventArgs^  e) {
    Question1 ^question1 = gcnew Question1();
    question1->Show();
    this->Hide();

}

Question1.h 我的问题1提示用户通过按钮选择两个可能的答案来回答问题。

Correct.h 正确答案会隐藏当前表单并打开另一个表示答案正确的表单:

    private: System::Void Answer1_Click(System::Object^  sender, System::EventArgs^  e) {
            Correct ^correct = gcnew Correct();
            correct->Show();
            this->Hide();

    }

第二个做同样的事情,除了它打开一个表明用户不正确的表格:

   private: System::Void Answer2_Click(System::Object^  sender, System::EventArgs^  e) {
            Incorrect ^incorrect = gcnew Incorrect();
            incorrect->Show();
            this->Hide();

    }

两种表单都允许用户通过单击同样隐藏正确/不正确表单的按钮来继续下一个问题。

Question2.h 现在这是我遇到困难的地方。我的Question2表单无法重新打开像Question1那样的正确/不正确的表单。我也无法访问主菜单。当我尝试重新打开Correct.h表单时,我收到错误'Question2':未声明的标识符。现在我怀疑这与我已经隐藏这些表格的事实有关,或者我的#includes要么是错误的顺序,要么是不正确的。

我的Question2.h表单看起来没有设计代码,因为它非常冗长:

    #pragma once
    #include "Correct.h"

    namespace QuizGame {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Question2
/// </summary>
public ref class Question2 : public System::Windows::Forms::Form
{
public:
    Question2(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Question2()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Label^  label1;
private: System::Windows::Forms::Button^  Answer1Correct;
private: System::Windows::Forms::Button^  Answer2Incorrect;
private: System::Windows::Forms::Button^  Answer3Incorrect;
private: System::Windows::Forms::Button^  Answer4Incorrect;
private: System::Windows::Forms::PictureBox^  pictureBox1;
protected:

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;


    #pragma endregion
private: System::Void Answer3Incorrect_Click(System::Object^  sender, System::EventArgs^  e) {
}

private: System::Void Answer2Incorrect_Click(System::Object^  sender, System::EventArgs^  e) {
}

private: System::Void Answer1Correct_Click(System::Object^  sender, System::EventArgs^  e) {
    Correct ^correct = gcnew Correct();
    correct->Show();
    this->Hide();
}
private: System::Void Answer4Incorrect_Click(System::Object^  sender, System::EventArgs^  e) {
}
   };
   }

如果这很难读,我很抱歉,这是我的第一次提交。如果这还不够,我很乐意发布更多代码(为了清楚起见,我试图将其保持在最低限度)。

0 个答案:

没有答案