.net 如何在工具箱中添加来自AxWMPLib::AxWindowsMediaPlayer的派生类?

.net 如何在工具箱中添加来自AxWMPLib::AxWindowsMediaPlayer的派生类?,.net,winforms,c++-cli,clr,axwindowsmediaplayer,.net,Winforms,C++ Cli,Clr,Axwindowsmediaplayer,这是一个CLR项目(.NET Framework 4.5) Microsoft Visual Studio社区2019 版本16.8.1 既然AxWMPLib::AxWindowsMediaPlayer继承自System::Windows::Forms::AxHost和AxHost继承自System::Windows::Forms::Control,为什么从ClassLibrary1.dll添加时Toolbox不支持它?相反,我得到了一个错误:ClassLibrary1.dll中没有可以放在工具

这是一个CLR项目(.NET Framework 4.5)

Microsoft Visual Studio社区2019 版本16.8.1

既然
AxWMPLib::AxWindowsMediaPlayer
继承自
System::Windows::Forms::AxHost
AxHost
继承自
System::Windows::Forms::Control
,为什么从
ClassLibrary1.dll
添加时
Toolbox
不支持它?相反,我得到了一个错误:ClassLibrary1.dll中没有可以放在工具箱中的组件。

这是我的
类库1.dll

#pragma once

using namespace System;

namespace ClassLibrary1 {
    public ref class Class1 : public AxWMPLib::AxWindowsMediaPlayer
    {
    public:
        Class1() {}
    };
}
适用于您的班级,例如:

[System::ComponentModel::ToolboxItem(true)]
public ref class MyMediaPlayer : public AxWMPLib::AxWindowsMediaPlayer
{
    ...
}

除了这个答案之外,重要的是要注意,如果有更多构造函数,则必须使用默认构造函数,因此必须显式声明默认构造函数,否则
Toolbox
将不接受它,另外,类和它的默认构造函数都必须有公共访问修饰符。我在Visual Studio Community 2019上发现了一个bug,或者不管是什么版本,也许你可以帮我解决这个问题。在设计器中添加从
AxWMPLib::AxWindowsMediaPlayer
派生的自定义控件时,如果在设计器中切换表单的语言,则设计器将全部为空,并强制关闭设计器。你知道那是什么吗?对于其他自定义控件,如派生自System::Windows::Forms*的控件,这不会发生。