0

I can do something as simple as:

  1. Create a new .NET form application
  2. Put a single RectangleShape onto the form
  3. add the following into the InitializeComponent method in the designer code

    Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or _
        ControlStyles.UserPaint Or _
        ControlStyles.DoubleBuffer, True)
    Me.UpdateStyles()
    
  4. Run the program
  5. Resize the form
  6. Watch angrily as the rectangle flickers

Is it possible to get rid of this? Or is the ShapeContainer internally flawed and I need to find a different solution?

Phil
  • 321
  • 2
  • 14

2 Answers2

2

It's fairly flawed. It uses its own window that's overlaid onto the form with the WS_EX_TRANSPARENT style turned on. That style makes it invisible, but also prevents any kind of double-buffering from working properly. Double-buffering the form has no effect, wrong window.

It is otherwise a rather expensive way to draw shapes. The cheap and flicker-free way is using e.Graphics.FillRectangle() in the form's OnPaint() override or Paint event handler.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Alright, well test it yourself - but I see quite the difference when double buffering the form. It still flickers with the form double buffered, but if you follow my steps - toggling the double buffer between runs - you should notice it. With that aside, thanks for your affirmation that the tool is flawed. I will use your suggestion. – Phil Jul 05 '11 at 18:47
0

I've never used the ShapeContainer but when ever I do custom graphics like that, I create a subclass for a Panel and in the constructor of my subclass I set DoubleBuffered to true.

More specific code example here.

Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
  • Yeah, sadly the ShapeContainer class is notinheritable. That was my first attempt as well: [Previous question](http://stackoverflow.com/questions/6553065/net-powerpacks-shapecontrol-any-way-to-double-buffer) – Phil Jul 05 '11 at 16:47