-2

I want to make a custom renderer for ToolStrip, but all the manuals and guides are written in C#.

Here is an example https://www.codeproject.com/Articles/29497/Custom-Rendering-for-the-ToolStrip-MenuStrip-and-S

I tried porting this code to C++, but I didn't really succeed, since I don't really understand C#.

How to do it in C++/CLI?

273K
  • 29,503
  • 10
  • 41
  • 64
MyDoomH
  • 11
  • 3
  • 1
    You do it in C++/CLI the exact same way you do in C#. It doesn't sound like you really made an attempt. If you have a question about a particular short snippet of C# that uses a feature C++ doesn't have, and searching came up with nothing, then ask about that small snippet. – Ben Voigt Aug 08 '22 at 16:27
  • Also note that article is terrible. You shouldn't ever add your own classes inside the `System.Windows.Forms` namespace, or anywhere else inside `System.*` or `Microsoft.* – Ben Voigt Aug 08 '22 at 16:29

1 Answers1

1

That's if anyone needs my solution to the problem...

CustomColorTable.h

namespace YourNamespace
{
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    public ref class CustomColorTable : public System::Windows::Forms::ProfessionalColorTable {
    public:
        Color _color = Color::DeepPink;
    public:
        property Color MenuBorder
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemBorder
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemPressedGradientBegin
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemPressedGradientEnd
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemPressedGradientMiddle
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemSelected
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemSelectedGradientBegin
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuItemSelectedGradientEnd
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuStripGradientBegin
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    public:
        property Color MenuStripGradientEnd
        {
        public: virtual Color get() override
        {
            return _color;
        };
        };
    };
}

In your form with MenuStrip

#include "CustomColorTable.h"

namespace YourNamespace 
{
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::Resources;
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            this->MenuStrip1->RenderMode = System::Windows::Forms::ToolStripRenderMode::System;
            this->MenuStrip1->Renderer = (gcnew System::Windows::Forms::ToolStripProfessionalRenderer(gcnew CustomColorTable()));
...

You can also do this for ToolStrip, you just need to change the names of the properties in CustomColorTable.h

Names of the properties can be found here

MyDoomH
  • 11
  • 3