在表单之间切换vc ++ 2010 [英] switching between forms vc++ 2010

查看:205
本文介绍了在表单之间切换vc ++ 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2010,我想在C ++中的两种形式之间切换。我一直在做一些搜索,我找不到任何解决方案,这不是所有关于c#和视觉基本。

I am using Visual Studio 2010 and I want to switch between two forms in C++. I have been doing some googling and I couldn't find any solution to this without it being all about c# and visual basic.

我得到这个错误到目前为止:

I have been getting this error so far:


错误12错误C2227:' - > ShowDialog的左侧必须指向class / struct / union / generic type
错误4错误C2065:'Form2':未声明标识符

错误11错误C2065:'f1':未声明标识符

错误5错误C2061:语法错误:标识符'Form2'

错误10错误C2061:语法错误:标识符'Form1'

Error 12 error C2227: left of '->ShowDialog' must point to class/struct/union/generic type Error 4 error C2065: 'Form2' : undeclared identifier
Error 11 error C2065: 'f1' : undeclared identifier
Error 5 error C2061: syntax error : identifier 'Form2'
Error 10 error C2061: syntax error : identifier 'Form1'

>
Form 1:

The only thing I put in my code is
Form 1:

#include "Form2.h"

和按钮事件

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

和表格2

#include "Form1.h"

p>

and for the button event

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

这是否正确?这是我的第一篇文章,所以告诉我还需要添加到
帮助使它更清楚
编辑:
Form2

Is this correct at all? This is my first post ever so tell what else I need to add in to help make it clearer Form2

#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();
     }

};
}


推荐答案

使用命名空间MBED4写入

In your implementation file you need to write

using namespace MBED4;

using MBED4::Form2;

之前

Form2^form2 = gcnew Form2();

或写

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

这篇关于在表单之间切换vc ++ 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆