.netwinformsc++-cliclraxwindowsmediaplayer

How to add a derived class from AxWMPLib::AxWindowsMediaPlayer in Toolbox?


This is a CLR Project (.NET Framework 4.5).

Microsoft Visual Studio Community 2019 Version 16.8.1

Since AxWMPLib::AxWindowsMediaPlayer inherits from System::Windows::Forms::AxHost and AxHost inherits from System::Windows::Forms::Control, why Toolbox does not support it when adding from ClassLibrary1.dll? Instead I got an error: There are no components in ClassLibrary1.dll that can be placed on the toolbox.

This is my ClassLibrary1.dll:

#pragma once

using namespace System;

namespace ClassLibrary1 {
    public ref class Class1 : public AxWMPLib::AxWindowsMediaPlayer
    {
    public:
        Class1() {}
    };
}

Solution

  • Apply [ToolboxItem(true)] to your class, for example:

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