C++ Visual Studio 2015 CLR Windows 窗体命名空间错误

C++ Visual Studio 2015 CLR Windows Form Namespace error

本文关键字:窗体 命名空间 错误 Windows CLR Visual Studio 2015 C++      更新时间:2023-10-16

嗨,我正在尝试创建一个函数,该函数想要为使用 Windows 表单向导创建的表单获取类。Visual Studio 正在使用项目名称作为窗体类"NewCustomerForm"的命名空间,但是当我尝试使用该类作为参数创建一个函数时,它说当我编译代码时,我收到以下错误消息:

Error   C2871   'Project1': a namespace with this name does not exist

这是它NewCustomerTab.h抱怨的文件:

#ifndef __NewCustomerTab_H__
#define __NewCustomerTab_H__
#include "NewCustomerForm.h"
using namespace Project1;
ref class CNewCustomerTab :
    public System::Windows::Forms::TabPage{
public:
    CNewCustomerTab(NewCustomerForm^);
private:
    System::Windows::Forms::Form^ form1;
};

这是表单类NewCustomerForm.h

#pragma once
#include "NewCustomerTab.h"
namespace Project1 {
    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 NewCustomerForm
    /// </summary>
    public ref class NewCustomerForm : public Form
    {
    public:
        NewCustomerForm(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }
    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~NewCustomerForm()
        {
            if (components)
            {
                delete components;
            }
        }
    public: System::Windows::Forms::Panel^  panel1;
    private: System::Windows::Forms::Label^  label1;
    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->label1 = (gcnew System::Windows::Forms::Label());
            this->panel1->SuspendLayout();
            this->SuspendLayout();
            // 
            // panel1
            // 
            this->panel1->Controls->Add(this->label1);
            this->panel1->Dock = System::Windows::Forms::DockStyle::Fill;
            this->panel1->Location = System::Drawing::Point(0, 0);
            this->panel1->Name = L"panel1";
            this->panel1->Size = System::Drawing::Size(842, 563);
            this->panel1->TabIndex = 0;
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->label1->Location = System::Drawing::Point(251, 31);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(229, 37);
            this->label1->TabIndex = 0;
            this->label1->Text = L"New Customer";
            // 
            // NewCustomerForm
            // 
            //this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            //this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(842, 563);
            this->Controls->Add(this->panel1);
            this->Name = L"NewCustomerForm";
            this->Text = L"NewCustomerForm";
            this->panel1->ResumeLayout(false);
            this->panel1->PerformLayout();
            this->ResumeLayout(false);
        }
#pragma endregion
    };
}

做错了什么,我包含 Form 类文件,它说Project1是一个命名空间。

必须使用公共语言运行时支持 (/clr) 进行编译。单击解决方案,在"配置属性"中选择"常规",然后为"公共语言运行时支持"选择"clr"。