Override Onpaint

What does it really mean when overriding the OnPaint event example if possible.

thank you


Answer this question

Override Onpaint

  • pmak

    I did use the override invalidate() for the rectangle. but still flickering occures. how can i force it not to draw the background

  • PerPixel

    Im trying to do double buffer. but i don't have access to the SetStyle with my panel. is it because i develop on a CF platform

  • Mapa3matuk

    I see. i will try to create a panel class. yeah CF programming is like hell.
    Cheers :)

  • Zulbaric

    but how to raise the overriden OnPaint event when we want to

  • ErikSR

    I don't think we can use override OnPaint().
    protected override void OnPaint(PaintEventArgs e)
    {
    }
    he is my onpaint. but I believe that the PaintEventArgs is only valid for forms and not panel.

  • Woyler

    OnPaint is a protected member of Control classes. It is called by the class when it wants to raise the Paint event, which indirectly means when it wants to paint.

    If you are creating a new control class, the recommended method of overriding the paint for that class is to override OnPaint perform you painting within OnPaint, optionally calling the base.OnPaint, or optionally raising the Paint event. See Control.OnPaint in MSDN for more information.

    If you're not creating a new class, you can only subscribe to the Paint event for a control and perform painting operations when you receive the paint event.



  • Ravi Kanth Koppala

    donkaiser wrote:
    I don't think we can use override OnPaint().
    protected override void OnPaint(PaintEventArgs e)
    {
    }
    he is my onpaint. but I believe that the PaintEventArgs is only valid for forms and not panel.
    A panel is more of a container for other controls, it's not really meant to do any of it's own painting.



  • coolcoder

    I dont think so. It's because that function is only allowed to be called from within that Panel class (source code that only Microsoft has) OR a class that you write that derives from the Panel class.

    The link I gave has source code snippets that demostrate this technique. That is, the technique of creating a custom Panel, that you can make SetStyle() calls on. (Look toward the end of that thread.)


  • AlexBar100

    donkaiser wrote:
    after researching i think it's impossible to raise the event whenever we want to. I try to find a way to prevent flikering in my application. panel.refresh() or panel.invalidate() won't help. Im developping in a CF2.0 so resources are very limited.
    Normally, if you know you need to repaint you call Invalidate(). If you know only a portion of your control needs to be repainted you can call the override of Invalidate() that takes a rectangle or a region to limit the amount of painting that needs to be done; thus reducing flicker.

    If you don't need to let the control draw it's own background (i.e. your control draws over its entire surface) you can set a style to force it not to do that. That is the most common way of reducing flicker.

    You can also double-buffer the drawing to reduce flicker even further.



  • TonyByers

    after researching i think it's impossible to raise the event whenever we want to. I try to find a way to prevent flikering in my application. panel.refresh() or panel.invalidate() won't help. Im developping in a CF2.0 so resources are very limited.

  • Chris4578

    Have you seen this thread yet It has all the answers you could ever want to your problem here.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=479866&SiteID=1


  • N B

    it's possible u send me ur code
    Even I create a new class for the panel, i still don't have access to the SetStyle function.
    my email is donkaiser@hotmail.com

    'Preciate

  • eclere

    I try to implement double buffer but i can't get the handle of the SetStyle method

    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    this.SetStyle(ControlStyles.DoubleBuffer, true);
    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    this.SetStyle(ControlStyles.DoubleBuffer, true);

    VS2005 give me the error saying that SetStyle and ControlStyles is not contained in the definition of the form.
    how can i get the handle on this function.

  • Shivapriya

    From within the class you can simply call OnPaint. Externally, you can simply call Invalidate on the control class which will eventually call OnPaint at the most approprate time.

  • Override Onpaint