Visual c++ Windows窗体应用程序:访问其他窗体中的元素visual studio 2012 c++; 访问(添加)Frim2元素到Frim1,用C++ VS2010工作得很好。 如果我在VisualStudio express 2012中从头开始尝试相同的操作,我会不断收到一个错误,说Form2是未声明的标识符。你知道怎么了吗 #include "stdafx.h" #include "Form2.h" .... Form2^ frm = gcnew Form2; this->Controls->Add(frm->panel1);
错误C2065:“Form2”:未声明的标识符 代码格式1: 包括“stdafx.h” 包括“表格2.h”Visual c++ Windows窗体应用程序:访问其他窗体中的元素visual studio 2012 c++; 访问(添加)Frim2元素到Frim1,用C++ VS2010工作得很好。 如果我在VisualStudio express 2012中从头开始尝试相同的操作,我会不断收到一个错误,说Form2是未声明的标识符。你知道怎么了吗 #include "stdafx.h" #include "Form2.h" .... Form2^ frm = gcnew Form2; this->Controls->Add(frm->panel1);,visual-c++,Visual C++,错误C2065:“Form2”:未声明的标识符 代码格式1: 包括“stdafx.h” 包括“表格2.h” #pragma一次 命名空间Windows窗体应用程序{ 使用名称空间系统; 使用名称空间System::ComponentModel; 使用名称空间系统::集合; 使用命名空间System::Windows::Forms; 使用名称空间System::Data; 使用名称空间系统::绘图; /// ///表格1摘要 /// public ref类Form1:public System
#pragma一次
命名空间Windows窗体应用程序{
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
///
///表格1摘要
///
public ref类Form1:public System::Windows::Forms::Form
{
公众:
表格1(无效)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
受保护的:
///
///清理所有正在使用的资源。
///
~Form1()
{
if(组件)
{
删除组件;
}
}
私有:系统::Windows::窗体::按钮^button1;
受保护的:
私人:
///
///必需的设计器变量。
///
系统::组件模型::容器^组件;
#pragma区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
void初始化组件(void)
{
此->按钮1=(gcnew System::Windows::Forms::Button());
此->SuspendLayout();
//
//按钮1
//
此->按钮1->位置=系统::图纸::点(31,32);
此->按钮1->名称=L“按钮1”;
该->按钮1->尺寸=系统::图纸::尺寸(75,27);
此->按钮1->选项卡索引=0;
此->按钮1->文本=L“按钮1”;
此->按钮1->UseVisualStyleBackColor=true;
此->按钮1->Click+=gcnewsystem::EventHandler(此,&Form1::按钮1\u Click);
//
//表格1
//
这->自动缩放尺寸=系统::图纸::尺寸(6,13);
这->AutoScaleMode=System::Windows::Forms::AutoScaleMode::Font;
这->ClientSize=System::Drawing::Size(284262);
此->控制->添加(此->按钮1);
此->名称=L“Form1”;
此->文本=L“Form1”;
此->恢复布局(错误);
}
#布拉格端区
私有:系统::无效按钮1\u单击(系统::对象^sender,系统::事件参数^e){
Form2^frm=gcnew Form2;
此->控制->添加(frm->面板1);
}
};
}
代码格式2:
#pragma once
namespace Windows_Forms_Application{
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;
}
}
public: System::Windows::Forms::Panel^ panel1;
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->panel1 = (gcnew System::Windows::Forms::Panel());
this->SuspendLayout();
//
// panel1
//
this->panel1->BackColor = System::Drawing::SystemColors::ActiveCaptionText;
this->panel1->Location = System::Drawing::Point(106, 85);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(132, 118);
this->panel1->TabIndex = 0;
//
// Form2
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->panel1);
this->Name = L"Form2";
this->Text = L"Form2";
this->ResumeLayout(false);
}
#pragma endregion
};
}
#pragma一次
命名空间Windows\u窗体\u应用程序{
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
///
///表格2摘要
///
public ref类Form2:public System::Windows::Forms::Form
{
公众:
表格2(无效)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
受保护的:
///
///清理所有正在使用的资源。
///
~Form2()
{
if(组件)
{
删除组件;
}
}
public:System::Windows::Forms::Panel^panel1;
受保护的:
私人:
///
///必需的设计器变量。
///
系统::组件模型::容器^组件;
#pragma区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
void初始化组件(void)
{
这->panel1=(gcnewsystem::Windows::Forms::Panel());
此->SuspendLayout();
//
//小组1
//
此->面板1->背景色=System::Drawing::SystemColor::ActiveCaptionText;
此->面板1->位置=系统::图纸::点(106,85);
此->面板1->名称=L“面板1”;
此->面板1->尺寸=系统::图纸::尺寸(132118);
此->面板1->选项卡索引=0;
//
//表格2
//
这->自动缩放尺寸=系统::图纸::尺寸(6,13);
这->AutoScaleMode=System::Windows::Forms::AutoScaleMode::Font;
这->ClientSize=System::Drawing::Size(284262);
此->控制->添加(此->面板1);
此->名称=L“Form2”;
此->文本=L“Form2”;
此->恢复布局(错误);
}
#布拉格端区
};
}
代码cpp:
// Windows Forms Application.cpp : main project file.
#include "stdafx.h"
#include "Form2.h"
#include "Form1.h"
using namespace WindowsFormsApplication;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
//Windows窗体应用程序.cpp:主项目文件。
#包括“stdafx.h”
#包括“表格2.h”
#包括“表格1.h”
使用命名空间WindowsFormsApplication;
[属性]
int main(数组^args)
{
//启用窗口
// Windows Forms Application.cpp : main project file.
#include "stdafx.h"
#include "Form2.h"
#include "Form1.h"
using namespace WindowsFormsApplication;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
#include "stdafx.h"
#include "Form2.h"
class form2;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
class form1;