How to open custom editor for property in PropertyGrid from the outside?

Compositing in .NET Custom Controls

  • 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!

  • Answer:

    The way to stop flickering is to understand the theory behind it an then apply it to your case. Basically, what you want to do is to prevent the window from drawing multiple times. You want a single draw. To do so, the usual strategies are to have a DC that is separate from the windows, let everything draw there, and then draw one time on the window. Other strategies include preventing window updates while things are happening (LockWindowUpdate?), and taking control of your background erasing. 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.

mpls2 at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

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.

jedicus

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.

mpls2

Have you tried using the SetStyle method on your custom control? http://msdn.microsoft.com/en-us/library/3t7htc9c(VS.80).aspx seems to suggest this should be done for custom controls. There's also http://www.msnewsgroups.net/group/microsoft.public.dotnet.languages.csharp/topic915.aspx http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic4241.aspx forum posts. Note sure if this'll help, but I saw no one was really answering, so I looked around a bit.

!Jim

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.