Is it possible to reference a user control in the

2019-07-29 12:07发布

问题:

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.