I have found the following hack:
1) Derive a class from
Forms::Panel
to expose the
SetStyle
method as public. Do this outside of
Form1.h
.
public ref class MyPanel : public System::Windows::Forms::Panel
{
public:
void SetStyle(System::Windows::Forms::ControlStyles flag, System::Boolean value)
{
System::Windows::Forms::Control::SetStyle(flag, value);
}
};
2) When it comes to changing the panel behavior (I do that in the main form constructor), cast the panel pointer the new class type.
static_cast<MyPanel^>(panel1)->SetStyle(ControlStyles::AllPaintingInWmPaint, true);
static_cast<MyPanel^>(panel1)->SetStyle(ControlStyles::DoubleBuffer, true);
This way, the code that the Designer parses remains perfectly untouched.