Is it possible to reference a user control in the same Windows::Forms project?

China☆狼群 提交于 2019-12-11 10:36:45

问题


I have a Windows::Forms application and I want to add a custom control to it (which basically displays some images and links them with some bezier curves I'm drawing).

I'm sure I've managed to get Windows Forms designer to display the custom controls in the same project before but I can't get it to work this time. It just says:

C++ CodeDOM parser error: Line: 524, Column: 33 --- Unknown type 'MyNamespace.MyCustomControl'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.

I'm creating the control explicitely mentioning the namespace (which I thought was what got this worknig last time):

#include "MyCustomControl.h"

namespace MyNamespace {

    public ref class MyGui: public System::Windows::Forms::Form
    {
    private: MyNamespace::MyCustomControl^  m_customControl;

    };
}

Is this just impossible or is there some peculiar workaround I'm missing?


回答1:


The Windows Forms Designer cannot reflect on mixed-mode EXEs. Make sure you compile with /clr:pure or move any class that require design time support (e.g. the components and controls on the form) to a class library project.



来源:https://stackoverflow.com/questions/4256037/is-it-possible-to-reference-a-user-control-in-the-same-windowsforms-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!