Cannot add Controls from 64-bit Assemblies to the Toolbox or Use in Designers Within the Visual Stud

今天在给Winform的主界面添加Windows Forms Control Library的控件时遇到了一个问题。

之前都是使用32位程序的,这次从开发阶段开始,就使用的64位编译环境,才遇到了这么一个棘手的问题。

可以概括为Cannot add Controls from 64-bit Assemblies to the Toolbox or Use in Designers Within the Visual Studio IDE。

经过调研,微软给出的解释是“ This behavior is by design. Visual Studio is a 32-bit process, and therefore can only execute 32-bit modules. While Visual Studio allows you to add a reference to a 64-bit assembly, it cannot actually JIT compile it to 64-bit and execute it in process.”

解决方法就是绕过界面设计器,添加引用时【Projects】里将整个工程都给添加引用进来,而不是使用【Browse】加入dll,怀疑是动态链接和静态链接的关系,有待调查。这时候,Form.h中通过手动添加代码,已经可以在主界面上显示自有的控件了,代码主要包括:

1) 添加引用;

2) 类中private下声明:VideoBrief::VideoBriefControl ^ VideoBriefControl1;

3) InitializeComponent中gcnew:VideoBriefControl1= gcnew VideoBrief::VideoBriefContro l();

4) 设置属性:

//

//VideoBriefControl1

//

VideoBriefControl1->BorderStyle= System::Windows::Forms::BorderStyle::Fixed3D;

VideoBriefControl1->Name= L”VideoBriefControl1”;

VideoBriefControl1->Dock= System::Windows::Forms::DockStyle::Fill;

5) Form中进行add:this->Controls->Add(VideoBriefControl1);

但是!Form1的界面设计器还是不能显示的,这就需要将没添加代码的Form文件备份一下,需要修改主界面时,直接替换掉。

Cannot add Controls from 64-bit Assemblies to the Toolbox or Use in Designers Within the Visual Studio IDE

发表评论

表情:
评论列表 (有 0 条评论,80人围观)

还没有评论,来说两句吧...

相关阅读