tags:

views:

319

answers:

1

I have been at this for a few days and it is driving me mad. I have a control that inherits from System.Windows.Forms.Panel and I'm trying to override OnPaint. It just plain, outright IGNORES it.

public class CollapsiblePanel : System.Windows.Forms.Panel
{
  public CollapsiblePanel()
  {
   //
   // Required for the Windows Form Designer
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
   SetStyle
    (
     ControlStyles.AllPaintingInWmPaint | 
     ControlStyles.UserPaint      | ControlStyles.DoubleBuffer   |
     ControlStyles.ResizeRedraw     | ControlStyles.Selectable ,
     true
    );
        }

  protected override void OnPaint(PaintEventArgs e)
  {
            // This never runs no matter what I try!
            base.OnPaint(e);
        }
}
+3  A: 

I have the same problem just with a ProgressBar, when i try to override the OnPaint.. It's never called.


I found the solution here: http://www.osix.net/modules/article/?id=826

You must create a constructor and enable user-painting like this: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);

Defualt values, probably vary depending on framework version and OS.

Hope that it helps

Joe
this worked, but for a different reason!! Apparently, the ORDER in which they go in actually matters (this doesn't make any sense - aren't enums just bit codes? ) - changing the order solved the problem for me.
Stacey