开发者

WinForms panels not painting when in stack

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜