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?
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