开发者

WinForms panels not painting when in stack

开发者 https://www.devze.com 2023-03-02 02:02 出处:网络
I have a Panel that has an image as a background.I\'ve added two panels (with transparent backgrounds) to this panel.I am responding to the onPaint event to draw things on them.

I have a Panel that has an image as a background. I've added two panels (with transparent backgrounds) to this panel. I am responding to the onPaint event to draw things on them.

only the panel in position 0 of the controls is being drawn.

any idea why?

EDIT: I am able to get the second child panel to show up by overriding the onPaint event of the containing Panel but the first child panel is painting twice. Is there a way to avoid this?

from the panel that contains the other ones

    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // VisualizationContainer
        // 
        this.AutoSize = true;
        this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this.Dock = System.Windows.Forms.DockStyle.Fill;
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.onPaint);
        this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.onMouseClick);
        this.Resize += new System.EventHandler(this.onResize);
        this.ResumeLayout(false);

    }

and the code from the containing panel's onPaint

private void onPaint(object sender, PaintEventArgs e)
    {
        InvokePaintBackground(this, e);

        foreach (SubPanel sub in subPanels)
        {
            sub.onPaint(this, e);
        }             
    }      
开发者_如何转开发
0

精彩评论

暂无评论...
验证码 换一张
取 消