开发者

OnPaint events order

开发者 https://www.devze.com 2023-03-01 23:23 出处:网络
I developed some components with their own OnPaint-override where I draw them. I now added a status panel which is designed to overlap topmost with part of my form. I use a alpha-blended color to gra

I developed some components with their own OnPaint-override where I draw them.

I now added a status panel which is designed to overlap topmost with part of my form. I use a alpha-blended color to gray out the underlying controls and display a text on it.

Unfortunately some of my underlying custom controls paint themselves after the status bar and so draw themselves above the status bar. Debugging I found out that first the status bar on paint event was called, later the paint event of the underlying controls.

How can I make sure the proper order is used to paint?

When underlying components draw 开发者_Go百科themselves the components infront of them should always be automatically invalidate so they redraw themselves but that is not happing. I also called SendToFront on the statusbar but that did not helper neither. So I am also asking what is the proper mechanism to maintain the order and how do the core components handle that.

Edit: I also run in this problem: With every run of my OnPaint-event my overlay gets more and more opaque because it draws with alpha=128--red again and again on itself.


To eliminate external factors (like variations between XP, Vista, Win7), you could:

  • blend the "status panel" graphics onto each control in their OnPaint handlers, so you don't need to mess about with a semi-transparent status window to achieve the desired display.

  • use one opaque control (essentially the status panel) and render the final image you want into it by compositing the graphics from the individual controls, which would elimimnate any uncertainty over how the rendering process will operate. This would mean that you'd have to add custom click handling, but that's usually a fairly trivial addition - one easy way around this is to put the main "display control" behind a set of invisible controls (the buttons) so that all the click handling can work as normal, but the painting is delegated to a single control.

0

精彩评论

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

关注公众号