2
votes

I've been working on one project last few months, and have one problem that I can't solve. I have a Windows form with controls on it. When user changes the controls size, app then fires sizechanged event and I move the controls on it accordingly. The main problem is with buttons because they have images - actually to be more precise - they are flat, no border, and have an image on it that's actually a drawn button(reason why I don't draw it by code is because the image is complex). On some machines they start to flicker when app is resizing. Form is set to DoubleBuffered true, and I've used this function to set double buffer on buttons.

public static void SetDoubleBuffered(System.Windows.Forms.Control c)
    {
        if (System.Windows.Forms.SystemInformation.TerminalServerSession)
            return;

        System.Reflection.PropertyInfo aProp =
              typeof(System.Windows.Forms.Control).GetProperty(
                    "DoubleBuffered",
                    System.Reflection.BindingFlags.NonPublic |
                    System.Reflection.BindingFlags.Instance);

        aProp.SetValue(c, true, null);
    }

Any suggestions?

1
When the form resizes, are you using any custom code to handle the resize event or just using the default code? If custom, are you suspending the layout of the form while all the controls are being resized or moved?Chris Thompson
I'm using custom code, and haven't use SuspendLayout, but I've tried it now and as far as I see same thing happens (will have to test it on another computer to see more clearly). I have approximately 10 buttons, and I change their left and top on SizeChanged event.n1tr0
The Button class already turns double-buffering on. Your problem lies elsewhere.Hans Passant
Some of the methods listed in that topic cause many bugs in my painting methods, so I'll need to test it a bit further.n1tr0

1 Answers

1
votes

This helped me a lot when I was having problems with double buffering. The code is a bit old, but is still covers the basics.

http://www.codeproject.com/KB/graphics/DoubleBuffering.aspx

Hope that helps. :)