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

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

vs2008中,使用VC++生成CLR工程之后,在窗体上随便添加一个控件(可显示的,比如文本框、静态框等),然后不做任何修改直接编译,但是编译不过。

在我的工程中,添加了两个控件,一个button,一个checkboxInitializeComponent()中的相关代码如下:

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(00));

this->button1->Name = L"button1";

this->button1->Size = (gcnew System::Drawing::Size(7523));

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(00));

this->checkBox1->Name = L"checkBox1";

this->checkBox1->Size = (gcnew System::Drawing::Size(10424));

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 ')'

这个错误表明,PointSize都不是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(00));   // 去掉了gcnew

this->button1->Name = L"button1";

this->button1->Size = (System::Drawing::Size(7523));   // 去掉了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(00));   // 去掉了gcnew

this->checkBox1->Name = L"checkBox1";

this->checkBox1->Size = (System::Drawing::Size(10424));   // 去掉了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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值