问题描述
这是一个 CLR 项目(.NET Framework 4.5)。
Microsoft Visual Studio 社区 2019 版本 16.8.1
既然AxWMPLib::AxWindowsMediaPlayer
继承自System::Windows::Forms::AxHost
,AxHost
继承自System::Windows::Forms::Control
,为什么Toolbox
从ClassLibrary1.dll
添加时不支持?相反,我收到了一个错误:ClassLibrary1.dll 中没有可以放置在工具箱上的组件。
这是我的ClassLibrary1.dll
:
#pragma once
using namespace System;
namespace ClassLibrary1 {
public ref class Class1 : public AxWMPLib::AxWindowsMediaPlayer
{
public:
Class1() {}
};
}
解决方法
将 [ToolboxItem(true)] 应用到您的班级,例如:
[System::ComponentModel::ToolboxItem(true)]
public ref class MyMediaPlayer : public AxWMPLib::AxWindowsMediaPlayer
{
...
}