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. Re-painting graphics

Re-painting graphics

Scheduled Pinned Locked Moved C#
graphicsquestionannouncement
4 Posts 3 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.
  • T Offline
    T Offline
    tjschilling
    wrote on last edited by
    #1

    I have a user control with a panel on it which I paint rectangles and text on using the following method - Graphics mg = this.CallsPanel.CreateGraphics(); When I minimize or switch back and forth between other application windows, I loose the graphics. I have been trying to figure out which event to wire a re-paint function to but am not having much luck. Or, is there a way to anchor the graphics that have been painted until I invalidate and update the panel?

    C 1 Reply Last reply
    0
    • T tjschilling

      I have a user control with a panel on it which I paint rectangles and text on using the following method - Graphics mg = this.CallsPanel.CreateGraphics(); When I minimize or switch back and forth between other application windows, I loose the graphics. I have been trying to figure out which event to wire a re-paint function to but am not having much luck. Or, is there a way to anchor the graphics that have been painted until I invalidate and update the panel?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      tjschilling wrote:

      Graphics mg = this.CallsPanel.CreateGraphics();

      NEVER do this. There is no way to solve the problem you're now having. Draw in your paint event and call Invalidate to force it to occur.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      T 1 Reply Last reply
      0
      • C Christian Graus

        tjschilling wrote:

        Graphics mg = this.CallsPanel.CreateGraphics();

        NEVER do this. There is no way to solve the problem you're now having. Draw in your paint event and call Invalidate to force it to occur.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        T Offline
        T Offline
        tjschilling
        wrote on last edited by
        #3

        I moved the calls to my re-draw to the paint event for the user control and all is well. Looks like you gave me what I needed. Thanks.

        G 1 Reply Last reply
        0
        • T tjschilling

          I moved the calls to my re-draw to the paint event for the user control and all is well. Looks like you gave me what I needed. Thanks.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Don't just do the re-draw in the Paint event, do all drawing there. Call the Invalidate method of the control when it needs to be redrawn. Make sure to use the Graphics object that is supplied in the EventArgs for the event, and not create your own. The supplied Graphics object is clipped to the area that should be redrawn, if you create a new one it won't be clipped, and you might draw on top of someone elses window.

          --- b { font-weight: normal; }

          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