您的位置:首页 > 其它

vs2008向导生成的CLR工程编译无法通过的解决方法

2009-05-08 10:04 525 查看
vs2008向导生成的CLR工程编译无法通过的解决方法

在vs2008中,使用VC++生成CLR工程之后,在窗体上随便添加一个控件(可显示的,比如文本框、静态框等),然后不做任何修改直接编译,但是编译不过。
在我的工程中,添加了两个控件,一个button,一个checkbox,InitializeComponent()中的相关代码如下:
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
//
// button1
//
this->button1->Location = (gcnew System::Drawing::Point(0, 0));
this->button1->Name = L"button1";
this->button1->Size = (gcnew System::Drawing::Size(75, 23));
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = (gcnew System::Drawing::Point(0, 0));
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = (gcnew System::Drawing::Size(104, 24));
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = L"checkBox1";
this->checkBox1->UseVisualStyleBackColor = true;
... ...
}
编译会有以下错误输出:
1>f:/exp/vs2008/project1/goWinService.h(79) : error C2039: 'Point' : is not a member of 'System::Drawing'
1>f:/exp/vs2008/project1/goWinService.h(79) : error C2061: syntax error : identifier 'Point'
1>f:/exp/vs2008/project1/goWinService.h(79) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(79) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(81) : error C2039: 'Size' : is not a member of 'System::Drawing'
1>f:/exp/vs2008/project1/goWinService.h(81) : error C2061: syntax error : identifier 'Size'
1>f:/exp/vs2008/project1/goWinService.h(81) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(81) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(89) : error C2039: 'Point' : is not a member of 'System::Drawing'
1>f:/exp/vs2008/project1/goWinService.h(89) : error C2061: syntax error : identifier 'Point'
1>f:/exp/vs2008/project1/goWinService.h(89) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(89) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(91) : error C2039: 'Size' : is not a member of 'System::Drawing'
1>f:/exp/vs2008/project1/goWinService.h(91) : error C2061: syntax error : identifier 'Size'
1>f:/exp/vs2008/project1/goWinService.h(91) : error C2143: syntax error : missing ';' before ')'
1>f:/exp/vs2008/project1/goWinService.h(91) : error C2143: syntax error : missing ';' before ')'
这个错误表明,Point和Size都不是System::Drawing的成员,手动在System::Drawing的后面添加“::”,结果的确只是出现了Design成员,没有其它任何成员,有点奇怪,然后上网上找,在msdn的论坛中找到了解决方法:
打开工程属性框,然后在Common Properties -> Framework and References中,在右侧的References添加新的引用,即从Add New Reference...弹出的对话框中,在.Net选项卡中选择System.Drawing,然后点确定添加进来即可。但是再编译时,又出现问题:
1>f:/exp/vs2008/project1/goWinService.h(79) : error C2664: 'System::Windows::Forms::Control::Location::set' : cannot convert parameter 1 from 'System::Drawing::Point ^' to 'System::Drawing::Point'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>f:/exp/vs2008/project1/goWinService.h(81) : error C2664: 'System::Windows::Forms::Control::Size::set' : cannot convert parameter 1 from 'System::Drawing::Size ^' to 'System::Drawing::Size'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>f:/exp/vs2008/project1/goWinService.h(89) : error C2664: 'System::Windows::Forms::Control::Location::set' : cannot convert parameter 1 from 'System::Drawing::Point ^' to 'System::Drawing::Point'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>f:/exp/vs2008/project1/goWinService.h(91) : error C2664: 'System::Windows::Forms::Control::Size::set' : cannot convert parameter 1 from 'System::Drawing::Size ^' to 'System::Drawing::Size'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
然后还是在刚才的贴子中,说明了问题所在,直接在InitializeComponent()中把对应行的gcnew去掉即可,修改后如下:
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
//
// button1
//
this->button1->Location = (System::Drawing::Point(0, 0)); // 去掉了gcnew
this->button1->Name = L"button1";
this->button1->Size = (System::Drawing::Size(75, 23)); // 去掉了gcnew
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = (System::Drawing::Point(0, 0)); // 去掉了gcnew
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = (System::Drawing::Size(104, 24)); // 去掉了gcnew
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = L"checkBox1";
this->checkBox1->UseVisualStyleBackColor = true;
... ...
}
再次编译,通过!
msdn的贴子网址:http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/3fe34263-2766-47a5-a8eb-f7581fcbef91/
如果网址无法打开,则在msdn中搜索字符串“'Point' : is not a member of 'System::Drawing'”,这个贴子的名称是:Still having trouble with custom controls
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐