How do I simultaneously display a container and its child controls?

How do I simultaneously display a container and its child controls

I have seen similar posts as this throughout the web and the community, but cannot seem to locate an answer. It seems the regions where controls are laid out are not invalidated by the container and show the window beneath.

I see this with switching between forms, but in my case I also see it when switching between tab pages. I have tried setting double-buffering through SetStyle and overriding OnPaintBackground for the controls, the parent container, the tab page... but nothing works. It doesn't matter how many controls are on the form, its just that its a little more noticeable with many controls. (Also note, this happens with both my custom controls and framework controls)

Basically, I think I'm looking for a painting technique for how to paint a container and it's children before displaying the container... or at the very least paint the background of the container so that windows behind it are not displayed (although the latter is not preferred).



Answer this question

How do I simultaneously display a container and its child controls?

  • ssuggs

    Yes, a container does paint itself and then its children. The question is whether there is a built in way to optimize the display (like double buffer an entire container) so that both the container and its children are rendered at the same time... so you don't get the domino effect of controls painted one at a time. My plan, unless someone has another suggestion, is to render the current page into a bitmap and blit it over the top of the one coming up...

    See these other similar posts...

    Hey, thanks for your responses :)


  • Gokhan Ertas

    A possible solution was to set WS_CLIPCHILDREN to false when a container goes through OnLayout. Then you would flip a bit so that children are clipped during normal painting. This looked promissing until applied to something like splitters where you get a lot of flicker. Also, it doesn't look real good since everything is your BackColor until the controls are drawn..but looks better than seeing what was behind the container previously. I still think I will have to use some sort of transition to take attention from the way this works in Windows.

    CommonGenius.com wrote:
    I would say you are probably not going to be able to find a fully dependable solution before Windows Vista.

    So, is the solution you talk about part of Vista or WPF Did they make a change in the GDI layer


  • tdanut

    I dont understand your problem. When a container control paints, it paints itself, then its children. What is it that you are trying to do differently

  • J. Skrzypiec

    I dont know if its built into Vista or if it was released as part of WPF. I havent had any time to play with it yet, I just read an article in the MSDN on it recently. If you do a quick search on MSDN you can probably find it.

  • FedericoAX

    The window painting scheme in Windows does not support this directly; however, the scheme in Windows Vista has been totally overhauled, and does support what you are looking for. If you can't wait, then one option would be to paint the children onto the same context as the one being passed to paint the container. For many controls this will work; however, for certain controls like textboxes and comboboxes, you might have to send a WM_PRINTCLIENT message to the child and call DoEvents to let the message be handled, and even then I'm not sure it would work. The problem is that Windows handles certain controls like textboxes in a special way, and you cant be sure that you ever have full control over its painting. In general, I would say you are probably not going to be able to find a fully dependable solution before Windows Vista.

  • How do I simultaneously display a container and its child controls?