OnPaint override is never called

前端 未结 2 1062
长情又很酷
长情又很酷 2021-01-04 02:19

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 plai

相关标签:
2条回答
  • 2021-01-04 02:44

    Call this.Invalidate() when you want to call OnPaint

    0 讨论(0)
  • 2021-01-04 02:53

    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://web.archive.org/web/20140214234801/http://osix.net/modules/article/?id=826

    You must create a constructor and enable user-painting like this:

    SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
    

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

    0 讨论(0)
提交回复
热议问题