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. Begin and End Drawing function in C#

Begin and End Drawing function in C#

Scheduled Pinned Locked Moved C#
csharpgraphics
4 Posts 2 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.
  • F Offline
    F Offline
    free_soul424
    wrote on last edited by
    #1

    Hi, Actually I want to draw many rectangles on the screen and want to show all of them at once. Is there any function like BeginUpdate and EndUpdate in c#. so that the drawing process is not shown to the viewer.

    E 1 Reply Last reply
    0
    • F free_soul424

      Hi, Actually I want to draw many rectangles on the screen and want to show all of them at once. Is there any function like BeginUpdate and EndUpdate in c#. so that the drawing process is not shown to the viewer.

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      No there isn't really, what you want is double-buffering, if you're using .NET 2 then there should be a DoubleBuffered property on the control you're inheriting from.  If not then use base.SetStyle in the constructor of the class. The BeginUpdate and EndUpdate are used in a different way, say you have a ListBox, if you want to add 1000 items to it normally each time you add an item the Invalidate method is called, this will cause the control to recalculate it's entire contents and redraw all of them.  If you use the Begin/EndUpdate pair then what this does is set a flag to say that when an item is added / deleted changed it's not meant to be redrawn.  When you call the EndUpdate function when all the items have been added then it calls the Invalidate method to redraw the control (and clears the flag). You can see the obvious benefits, in the first method (no Begin/EndUpdate) the control is redrawn 1000 times as each item is added (thus producing a flicker (unless you have an awesomely specced machine)), in the second it only redraws once when everything has finished.

      F 1 Reply Last reply
      0
      • E Ed Poore

        No there isn't really, what you want is double-buffering, if you're using .NET 2 then there should be a DoubleBuffered property on the control you're inheriting from.  If not then use base.SetStyle in the constructor of the class. The BeginUpdate and EndUpdate are used in a different way, say you have a ListBox, if you want to add 1000 items to it normally each time you add an item the Invalidate method is called, this will cause the control to recalculate it's entire contents and redraw all of them.  If you use the Begin/EndUpdate pair then what this does is set a flag to say that when an item is added / deleted changed it's not meant to be redrawn.  When you call the EndUpdate function when all the items have been added then it calls the Invalidate method to redraw the control (and clears the flag). You can see the obvious benefits, in the first method (no Begin/EndUpdate) the control is redrawn 1000 times as each item is added (thus producing a flicker (unless you have an awesomely specced machine)), in the second it only redraws once when everything has finished.

        F Offline
        F Offline
        free_soul424
        wrote on last edited by
        #3

        Hi, thanks for reply, actually I am drawing almost 10000 rectangles on the screen. My main function of drawing is called in the form PAINT function. I have enabled the double buffered property but it is not working. Can you give me a bit more detail? Thanks for help.

        E 1 Reply Last reply
        0
        • F free_soul424

          Hi, thanks for reply, actually I am drawing almost 10000 rectangles on the screen. My main function of drawing is called in the form PAINT function. I have enabled the double buffered property but it is not working. Can you give me a bit more detail? Thanks for help.

          E Offline
          E Offline
          Ed Poore
          wrote on last edited by
          #4

          My only suggestion would be to move any position calculations to outside the Paint function because that is called more often.  I.e. do as few mathematical calculations for the positioning / size of the elements in the Paint event, do that inside the Resize.

          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