如何从工具箱中的 AxWMPLib::AxWindowsMediaPlayer 添加派生类?

问题描述

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

Microsoft Visual Studio 社区 2019 版本 16.8.1

既然AxWMPLib::AxWindowsMediaPlayer继承自System::Windows::Forms::AxHostAxHost继承自System::Windows::Forms::Control,为什么ToolBoxClassLibrary1.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
{
    ...
}