Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. override onpaint

override onpaint

Scheduled Pinned Locked Moved C#
tutorialquestion
19 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D donkaiser

    yes i main concern is flikering because at every update of my drawing the whole thing got redrawn. panel.invalidate() and panel.refresh() fliker the screen. Is there a solution for that of by the way im developing in the CF 2.0. so possibilities are very limited. Donkaiser

    M Offline
    M Offline
    mikanu
    wrote on last edited by
    #10

    In order to reduce flickering you may have to use a technique which is commonly reffered to double-buffering. What that means is that you create graphics context in the background and draw there. When you're done, you 'swap' the two graphics contexts. What that means is that you basically copy the back buffer graphics context's contents to the active graphics context. A quick search for double buffering will most likely give you all the information that you need. ---- www.digitalGetto.com

    D 1 Reply Last reply
    0
    • M Martin 0

      How is that possible? :confused:

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #11

      Call _Control_.Invalidate(). This will invalidate the entire region of the control and force a WM_PAINT message to be sent to the control's window. This message is what triggers the OnPaint event. Dave Kreskowiak Microsoft MVP - Visual Basic

      M 1 Reply Last reply
      0
      • M mikanu

        In order to reduce flickering you may have to use a technique which is commonly reffered to double-buffering. What that means is that you create graphics context in the background and draw there. When you're done, you 'swap' the two graphics contexts. What that means is that you basically copy the back buffer graphics context's contents to the active graphics context. A quick search for double buffering will most likely give you all the information that you need. ---- www.digitalGetto.com

        D Offline
        D Offline
        donkaiser
        wrote on last edited by
        #12

        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 to use on a panel to prevent flickering? Donkaiser Donkaiser

        M 1 Reply Last reply
        0
        • I Ista

          you can also override the PaintBackground. But the problem is because you see the client area when it redraws. You should create an off screen buffer. write to it, then write to the client after its all done. then you wont see any flicker. WinForms is not a very good graphical program. And this is very complicated. I recommend an MFC book to fully understand how to control painting. Although a method may exist to limit the flickering. I dont know of one and I use API's to contol that. But, a little flicker is okay for a business program. Nick 1 line of code equals many bugs. So don't write any!!

          L Offline
          L Offline
          LongRange Shooter
          wrote on last edited by
          #13

          Actually, if you set the style of the control to OptimizedDoubleBuffer it will handle all of the double buffer work for you. That is if you are using VS 2005

          1 Reply Last reply
          0
          • D donkaiser

            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 to use on a panel to prevent flickering? Donkaiser Donkaiser

            M Offline
            M Offline
            mikanu
            wrote on last edited by
            #14

            I'm not 100% sure but I think if you want to use the standard doublebuffering that .NET 2.0 GDI+ is offering you have to implement some other functions to support it. Make sure you find a good article on that. It's not trivial at first but once you grasp the fundamentals it should be straight forwards. Also, did you mention using the Compact Framework?! That may be the reason. Google for an example of how to implement double buffering in C# with .NET 1.0/1.1... that is not using the .SetStyle and ControlStyles.DoubleBuffer. Good luck ---- www.digitalGetto.com

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              Call _Control_.Invalidate(). This will invalidate the entire region of the control and force a WM_PAINT message to be sent to the control's window. This message is what triggers the OnPaint event. Dave Kreskowiak Microsoft MVP - Visual Basic

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #15

              Sorry missunderstanding, I was wondering about... " You could raise the paint event yourself, but that is not recommended. " How can you do that? Thanks for more Info, Martin -- modified at 15:15 Thursday 29th June, 2006

              D 1 Reply Last reply
              0
              • M Martin 0

                Sorry missunderstanding, I was wondering about... " You could raise the paint event yourself, but that is not recommended. " How can you do that? Thanks for more Info, Martin -- modified at 15:15 Thursday 29th June, 2006

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #16

                Simply call Invalidate anywhere else in the control's code, except inside the Paint handler. Dave Kreskowiak Microsoft MVP - Visual Basic

                M 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Simply call Invalidate anywhere else in the control's code, except inside the Paint handler. Dave Kreskowiak Microsoft MVP - Visual Basic

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #17

                  Sorry again, You can really believe me when I'm saiing that I understand the Invalidate Method. What I did not understand is what Guffa said before. But maybe, my C# is better than my english. Thank again, Martin

                  D 1 Reply Last reply
                  0
                  • M Martin 0

                    Sorry again, You can really believe me when I'm saiing that I understand the Invalidate Method. What I did not understand is what Guffa said before. But maybe, my C# is better than my english. Thank again, Martin

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #18

                    What he means is that you should NOT call the Paint method directly. If you do, you can have very unexpected and strange results. You should only be painting the control when Windows expects you to. When it wants you to repaint, it'll send the WM_PAINT message to your control, thereby firing the Paint event. When you call Invalidate, your telling the control to invalidate its client area. You haven't actually fired the Paint event. The control will let Windows know that it has to repaint itself. Windows will then figure out when it is safe for you to repaint your window and send back the paint message when it is appropriate for you to repaint. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 19:17 Thursday 29th June, 2006

                    M 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      What he means is that you should NOT call the Paint method directly. If you do, you can have very unexpected and strange results. You should only be painting the control when Windows expects you to. When it wants you to repaint, it'll send the WM_PAINT message to your control, thereby firing the Paint event. When you call Invalidate, your telling the control to invalidate its client area. You haven't actually fired the Paint event. The control will let Windows know that it has to repaint itself. Windows will then figure out when it is safe for you to repaint your window and send back the paint message when it is appropriate for you to repaint. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 19:17 Thursday 29th June, 2006

                      M Offline
                      M Offline
                      Martin 0
                      wrote on last edited by
                      #19

                      Ohhhhhhhhhhhhhhhhhh, You mean "this.OnPaint(....)"; But its the first time we are speaking of a method. "What he means is that you should NOT call the Paint method directly" Now I got it. Thank you so much for your time Dave. Martin

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups