我有一个具有透明背景的面板。当我将其中一些添加到控件时,具有最高索引的子元素会呈现在顶部。有人可以告诉我发生了什么以及如何解决这个问题吗?
这是面板的代码:
public ref class TransparentPanel : public Panel
{
public:
Bitmap^ _image;
TransparentPanel(Bitmap^ image){_image = image;Width = image->Width;Height = image->Height;}
virtual property System::Windows::Forms::CreateParams^ CreateParams{
System::Windows::Forms::CreateParams^ get(void) override {
System::Windows::Forms::CreateParams^ cp = Panel::CreateParams;
cp->ExStyle |= 0x00000020;//WS_EX_TRANSPARENT
return cp;
}
}
virtual void OnPaintBackground(PaintEventArgs^ e) override {}
virtual void OnPaint(PaintEventArgs^ e) override {e->Graphics->DrawImage(_image, Rectangle(0, 0, Width, Height));}
};