Forms Microsoft Visual C++;2010年开放另一种形式 我试图使它在我点击VisualC++项目的按钮时,打开另一个窗体,就像java joptPias.Sujin对话框一样,但是使它看起来像我想要的样子。我试图用Form21^form2=gcnewform21()打开它;form2->ShowDialog() 但它所说的是 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2065: 'Form21' : undeclared identifier 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2065: 'form2' : undeclared identifier 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2061: syntax error : identifier 'Form21' 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(254): error C2065: 'form2' : undeclared identifier 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(254): error C2227: left of '->ShowDialog' must point to class/struct/union/generic type 1> type is ''unknown-type''

Forms Microsoft Visual C++;2010年开放另一种形式 我试图使它在我点击VisualC++项目的按钮时,打开另一个窗体,就像java joptPias.Sujin对话框一样,但是使它看起来像我想要的样子。我试图用Form21^form2=gcnewform21()打开它;form2->ShowDialog() 但它所说的是 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2065: 'Form21' : undeclared identifier 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2065: 'form2' : undeclared identifier 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2061: syntax error : identifier 'Form21' 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(254): error C2065: 'form2' : undeclared identifier 1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(254): error C2227: left of '->ShowDialog' must point to class/struct/union/generic type 1> type is ''unknown-type'',forms,c++-cli,Forms,C++ Cli,表格2应该很好,但这里是代码 #pragma once namespace Lesson2 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using

表格2应该很好,但这里是代码

#pragma once

namespace Lesson2 {

    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 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::Label^  label1;
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::TextBox^  textBox2;
    protected: 

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

#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->label1 = (gcnew System::Windows::Forms::Label());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(12, 9);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(61, 13);
            this->label1->TabIndex = 0;
            this->label1->Text = L"Username :";
            this->label1->Click += gcnew System::EventHandler(this, &Form2::label1_Click);
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(81, 8);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(108, 20);
            this->textBox1->TabIndex = 1;
            this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form2::textBox1_TextChanged);
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(12, 54);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(59, 13);
            this->label2->TabIndex = 2;
            this->label2->Text = L"Password: ";
            // 
            // textBox2
            // 
            this->textBox2->Location = System::Drawing::Point(81, 47);
            this->textBox2->Name = L"textBox2";
            this->textBox2->Size = System::Drawing::Size(108, 20);
            this->textBox2->TabIndex = 3;
            // 
            // Form2
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(211, 88);
            this->Controls->Add(this->textBox2);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->label1);
            this->DoubleBuffered = true;
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
            this->MaximizeBox = false;
            this->MinimizeBox = false;
            this->Name = L"Form2";
            this->Text = L"Create an account";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             }
};
}
#pragma一次
名称空间第二课{
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
/// 
///表格2摘要
/// 
public ref类Form2:public System::Windows::Forms::Form
{
公众:
表格2(无效)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
受保护的:
/// 
///清理所有正在使用的资源。
/// 
~Form2()
{
if(组件)
{
删除组件;
}
}
私有:系统::Windows::窗体::标签^label1;
private:System::Windows::Forms::TextBox^textBox1;
私有:系统::Windows::窗体::标签^label2;
private:System::Windows::Forms::TextBox^textBox2;
受保护的:
私人:
/// 
///必需的设计器变量。
/// 
系统::组件模型::容器^组件;
#pragma区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
void初始化组件(void)
{
这->标签1=(gcnewsystem::Windows::Forms::Label());
这->textBox1=(gcnewsystem::Windows::Forms::TextBox());
这->label2=(gcnewsystem::Windows::Forms::Label());
这->textBox2=(gcnewsystem::Windows::Forms::TextBox());
此->SuspendLayout();
// 
//标签1
// 
此->标签1->自动调整大小=真;
该->标签1->位置=系统::图纸::点(12,9);
此->标签1->名称=L“标签1”;
该->标签1->尺寸=系统::图纸::尺寸(61,13);
此->标签1->选项卡索引=0;
此->标签1->文本=L“用户名:”;
this->label1->Click+=gcnewsystem::EventHandler(this,&Form2::label1\u Click);
// 
//文本框1
// 
此->文本框1->位置=系统::绘图::点(81,8);
此->textBox1->Name=L“textBox1”;
这->文本框1->尺寸=系统::图纸::尺寸(108,20);
此->文本框1->选项卡索引=1;
this->textBox1->TextChanged+=gcnewsystem::EventHandler(this,&Form2::textBox1\u TextChanged);
// 
//标签2
// 
此->标签2->自动调整大小=真;
该->标签2->位置=系统::图纸::点(12,54);
此->label2->名称=L“label2”;
这个->标签2->尺寸=系统::图纸::尺寸(59,13);
此->标签2->选项卡索引=2;
此->标签2->文本=L“密码:”;
// 
//文本框2
// 
此->文本框2->位置=系统::绘图::点(81,47);
此->textBox2->Name=L“textBox2”;
这->文本框2->尺寸=系统::图纸::尺寸(108,20);
此->文本框2->选项卡索引=3;
// 
//表格2
// 
这->自动缩放尺寸=系统::图纸::尺寸(6,13);
这->AutoScaleMode=System::Windows::Forms::AutoScaleMode::Font;
这->ClientSize=System::Drawing::Size(21188);
此->控制->添加(此->文本框2);
此->控制->添加(此->标签2);
此->控制->添加(此->文本框1);
此->控制->添加(此->标签1);
此->双缓冲=真;
这->FormBorderStyle=System::Windows::Forms::FormBorderStyle::FixedSingle;
此->MaximizeBox=false;
此->最小化ebox=false;
此->名称=L“Form2”;
此->文本=L“创建帐户”;
此->恢复布局(错误);
此->执行布局();
}
#布拉格端区
私有:系统::无效标签1_单击(系统::对象^sender,系统::事件参数^e){
}
私有:系统::Void textBox1\u TextChanged(系统::对象^sender,系统::EventArgs ^e){
}
};
}

我知道它说的是第二课,但那只是因为我在自学一些东西。我学这种东西很容易。除非发生这种情况。有人看到哪里出了问题吗?

Form21很可能是在另一个文件中声明的,因此编译器找不到Form21类型

在Form1.h的顶部,添加
#include“Form21.h”
(或者包含Form21类声明的头文件的名称,如果它不同的话)

我还建议您阅读有关头文件和cpp文件(头文件中似乎有代码)、转发声明和其他一些关于c++/cli的基本内容

编辑:发布
Form2
code后,错误是行
Form21^Form2=gcnewform21()应该是
Form2^Form2=gcnewform2()。您声明了
Form2
,而不是
Form21


祝你好运

不是C++大师,但似乎FULL 21有什么不对,也许是它声明后的一个丢失的分号?你是否包括了Frav2.H.@ THEYSTEVE13?你能把那个文件中的代码添加到你的问题吗?是的,我会的。这只是一个简单的生成表单,但效果很好!我不知道为什么它将我的文件命名为Form21.h,但希望将其命名为Form2。谢谢