0

我正在使用 Visual C++ 2010 开发 Windows 窗体应用程序。我正在尝试使用列表(System::Collections::Generic::List)。直到某个时刻,一切都很好。然后,出于我看不到的特殊原因,设计师开始不承认 Link^ 是一种类型。错误信息是:

" C++ CodeDOM 解析器错误:行:70,列:17 --- 未知类型 'System.Collections.Generic.List^'。请确保引用了包含此类型的程序集。如果此类型是您的一部分开发项目,请确保项目已成功构建。

奇怪的是项目构建和运行完美,唯一导致问题的是设计器。

这是代码的重要(据我所知)部分:

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::Collections::Generic; //I only added this line

private: System::Collections::Generic::List<String^>^ MyText;
//Manually added the line above
private: System::Windows::Forms::Button^  button1;

void InitializeComponent(void)
{    
    this->MyText = (gcnew System::Collections::Generic::List<String^>());
    //again, added the line above
    this->button1 = (gcnew System::Windows::Forms::Button());
}

//and this is how I'm currently using the List
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
{
    textBox1->Text = MyText->Count + " " + MyText->Capacity;
}
// textBox1->Text becomes 0 0

我已经尝试过 System::Collections::Generic::List^ MyText 和 List^ MyText,(因为我添加了using namespace System::Collections::Generic)但它仍然给我错误消息。

我已经用 List 注释掉了一些代码,设计器工作得很好,但是当我把代码放回去时,错误又回来了。我无数次尝试重新启动 Visual C++,从项目中删除文件并再次添加,结果总是一样:项目构建,设计器不起作用。我正式没有想法,所以......有什么帮助吗?

(哦,另外,有一个选项可以跳过错误,它确实会在大多数情况下正常显示设计器,但是,当您单击该选项时程序会发出警告,有时它会显示设计器缺少一些控件并且代码块从 Form1.h 中消失)

4

0 回答 0