在表单vc ++ 2010之间切换

时间:2014-11-03 16:51:35

标签: visual-studio-2010 c++-cli

我正在使用Visual Studio 2010,我想在C ++中切换两个表单。我一直在做一些谷歌搜索,如果没有全部关于c#和visual basic的话,我无法找到任何解决方案。

到目前为止,我一直收到此错误:

  

错误12错误C2227:左边的' - > ShowDialog'必须指向class / struct / union / generic类型   错误4错误C2065:' Form2' :未声明的标识符
  错误11错误C2065:' f1' :未声明的标识符
  错误5错误C2061:语法错误:标识符' Form2'
  错误10错误C2061:语法错误:标识符' Form1'

我在代码中唯一提到的是
表格1:

#include "Form2.h"

和按钮事件

Form2^form2 = gcnew Form2();
form2->ShowDialog();
this->Hide();

并以表格2

#include "Form1.h"

和按钮事件

Form1^f1 = gcnew Form1();
this->Hide();
f1->ShowDialog();

这是否正确?这是我的第一篇文章,所以告诉我还需要添加什么 帮助使它更清晰  编辑: 窗体2

#pragma once
#include "Form1.h"

namespace MBED4 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;          // *** added to allow listing of COM ports
using namespace System::Threading;     
/// <summary>
/// Summary for Form2
/// </summary>
public ref class Form2 : public System::Windows::Forms::Form
{

public:

    Form2(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form2()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Button^  button1;
protected: 
private: System::Windows::Forms::Button^  button2;
private: System::Windows::Forms::Button^  button3;
private: System::Windows::Forms::Button^  button4;
private: System::Windows::Forms::Button^  button5;
private: System::Windows::Forms::Button^  button6;
private: System::Windows::Forms::Button^  button7;
private: System::Windows::Forms::MenuStrip^  menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^  fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  exitToolStripMenuItem;
private: System::IO::Ports::SerialPort^  serialPort1;
private: System::ComponentModel::IContainer^  components;

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>


 #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->components = (gcnew System::ComponentModel::Container());
        this->button1 = (gcnew System::Windows::Forms::Button());
        this->button2 = (gcnew System::Windows::Forms::Button());
        this->button3 = (gcnew System::Windows::Forms::Button());
        this->button4 = (gcnew System::Windows::Forms::Button());
        this->button5 = (gcnew System::Windows::Forms::Button());
        this->button6 = (gcnew System::Windows::Forms::Button());
        this->button7 = (gcnew System::Windows::Forms::Button());
        this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
        this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
        this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
        this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
        this->menuStrip1->SuspendLayout();
        this->SuspendLayout();
        // 
        // button1
        // 
        this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12,                                 System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button1->Location = System::Drawing::Point(29, 41);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(80, 30);
        this->button1->TabIndex = 0;
        this->button1->Text = L"Servo1";
        this->button1->UseVisualStyleBackColor = true;
        // 
        // button2
        // 
        this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button2->Location = System::Drawing::Point(29, 97);
        this->button2->Name = L"button2";
        this->button2->Size = System::Drawing::Size(80, 30);
        this->button2->TabIndex = 1;
        this->button2->Text = L"Servo2";
        this->button2->UseVisualStyleBackColor = true;
        // 
        // button3
        // 
        this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button3->Location = System::Drawing::Point(29, 152);
        this->button3->Name = L"button3";
        this->button3->Size = System::Drawing::Size(80, 30);
        this->button3->TabIndex = 2;
        this->button3->Text = L"Servo3";
        this->button3->UseVisualStyleBackColor = true;
        // 
        // button4
        // 
        this->button4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button4->Location = System::Drawing::Point(29, 203);
        this->button4->Name = L"button4";
        this->button4->Size = System::Drawing::Size(80, 30);
        this->button4->TabIndex = 3;
        this->button4->Text = L"Servo4";
        this->button4->UseVisualStyleBackColor = true;
        // 
        // button5
        // 
        this->button5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button5->Location = System::Drawing::Point(29, 273);
        this->button5->Name = L"button5";
        this->button5->Size = System::Drawing::Size(113, 40);
        this->button5->TabIndex = 4;
        this->button5->Text = L"User Mode";
        this->button5->UseVisualStyleBackColor = true;
        this->button5->Click += gcnew System::EventHandler(this, &Form2::button5_Click);
        // 
        // button6
        // 
        this->button6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button6->Location = System::Drawing::Point(157, 41);
        this->button6->Name = L"button6";
        this->button6->Size = System::Drawing::Size(80, 30);
        this->button6->TabIndex = 5;
        this->button6->Text = L"LED1";
        this->button6->UseVisualStyleBackColor = true;
        // 
        // button7
        // 
        this->button7->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->button7->Location = System::Drawing::Point(157, 97);
        this->button7->Name = L"button7";
        this->button7->Size = System::Drawing::Size(80, 30);
        this->button7->TabIndex = 6;
        this->button7->Text = L"LED2";
        this->button7->UseVisualStyleBackColor = true;
        // 
        // menuStrip1
        // 
        this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->fileToolStripMenuItem});
        this->menuStrip1->Location = System::Drawing::Point(0, 0);
        this->menuStrip1->Name = L"menuStrip1";
        this->menuStrip1->Size = System::Drawing::Size(570, 24);
        this->menuStrip1->TabIndex = 7;
        this->menuStrip1->Text = L"menuStrip1";
        // 
        // fileToolStripMenuItem
        // 
        this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->exitToolStripMenuItem});
        this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
        this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
        this->fileToolStripMenuItem->Text = L"File";
        // 
        // exitToolStripMenuItem
        // 
        this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
        this->exitToolStripMenuItem->Size = System::Drawing::Size(152, 22);
        this->exitToolStripMenuItem->Text = L"Exit";
        this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form2::exitToolStripMenuItem_Click);
        // 
        // Form2
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(570, 344);
        this->Controls->Add(this->button7);
        this->Controls->Add(this->button6);
        this->Controls->Add(this->button5);
        this->Controls->Add(this->button4);
        this->Controls->Add(this->button3);
        this->Controls->Add(this->button2);
        this->Controls->Add(this->button1);
        this->Controls->Add(this->menuStrip1);
        this->MainMenuStrip = this->menuStrip1;
        this->Name = L"Form2";
        this->Text = L"Form2";
        this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
        this->menuStrip1->ResumeLayout(false);
        this->menuStrip1->PerformLayout();
        this->ResumeLayout(false);
        this->PerformLayout();

    }
  #pragma endregion
  private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {
         }
private: System::Void exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
             serialPort1->Close();
             Application::Exit();
         }
 private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
    Form1^f1 = gcnew Form1();
    this->Hide();
    f1->ShowDialog();
     }

};
}

1 个答案:

答案 0 :(得分:0)

在您的实施文件中,您需要编写

using namespace MBED4;

using MBED4::Form2;

Form2^form2 = gcnew Form2();

或写

MBED4::Form2^form2 = gcnew MBED4::Form2();
form2->ShowDialog();
this->Hide();