Compositing in .NET Custom Controls
May 19, 2008 10:28 AM Subscribe
How do I prevent flicker in my .NET app?
I have a custom control and I'd like the contents of this control to draw in a very snappy way, meaning I basically want the contents (a bunch of Labels) to appear fully drawn at the same time.
Obviously, this calls for double-buffering. I know about the Control.DoubleBuffer property, but that only double buffers each control individually. I want the contents of my custom control to be composited and drawn to a single back-buffer before being blitted.
My current solution doesn't use a custom control at all, but rather draws each label on a bitmap and blits that to the screen. This is not very elegant, so I'm refactoring to use custom controls, but the flicker is a deal-breaker for me.
What's the simplest way for me to achieve my goal?
Thanks!
I have a custom control and I'd like the contents of this control to draw in a very snappy way, meaning I basically want the contents (a bunch of Labels) to appear fully drawn at the same time.
Obviously, this calls for double-buffering. I know about the Control.DoubleBuffer property, but that only double buffers each control individually. I want the contents of my custom control to be composited and drawn to a single back-buffer before being blitted.
My current solution doesn't use a custom control at all, but rather draws each label on a bitmap and blits that to the screen. This is not very elegant, so I'm refactoring to use custom controls, but the flicker is a deal-breaker for me.
What's the simplest way for me to achieve my goal?
Thanks!
I agree with markovich. Coordinating the drawing done by several custom controls will be more complicated than your current approach, especially if the controls are non-interactive, as yours seem to be.
posted by jedicus at 10:50 AM on May 19, 2008
posted by jedicus at 10:50 AM on May 19, 2008
Response by poster: I'm wondering if there's a way to use the Windows Forms infrastructure to basically do what I'm doing now, by overloading OnPaint() or whatever.
posted by mpls2 at 11:01 AM on May 19, 2008
posted by mpls2 at 11:01 AM on May 19, 2008
Have you tried using the SetStyle method on your custom control? MSDN seems to suggest this should be done for custom controls.
There's also a couple forum posts.
Note sure if this'll help, but I saw no one was really answering, so I looked around a bit.
posted by !Jim at 1:00 AM on May 20, 2008
There's also a couple forum posts.
Note sure if this'll help, but I saw no one was really answering, so I looked around a bit.
posted by !Jim at 1:00 AM on May 20, 2008
This thread is closed to new comments.
It is not elegant AT ALL to use a bunch of controls within a control. There is quite some overhead involved. The elegant approach is to draw the labels in memory and blit to the window...like you seem to have been doing.
posted by markovich at 10:36 AM on May 19, 2008