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. [Solved] Clearing control of graphics before painting [modified]

[Solved] Clearing control of graphics before painting [modified]

Scheduled Pinned Locked Moved C#
questiongraphics
3 Posts 2 Posters 4 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.
  • J Offline
    J Offline
    Jordanwb
    wrote on last edited by
    #1

    I have a class called CardHolder which extends UserControl. I have overrode its OnPaint function like so: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; foreach (Card c in this.Controls) { g.DrawImage(c.Image, c.Location); } } Each image is tied to a Control which has been added to this control. Each image is a partially transparent image which is partially overlaid another image. However, each time the OnPaint function is called, it doesn't clear the Control of what was there before: Good: http://img20.imageshack.us/i/goodw.jpg/[^] Oh dear: http://img24.imageshack.us/i/ohdearz.jpg/[^] I've hooked into the CardHolder's Resize event and call PositionCards in that function to position the Controls, which in turn calls OnPaint behind the scenes. I hope what I'm doing here makes sense to you guys. How do I clear the Control of the previously drawn images? Card extends UserControl as well but is transparent and has no child controls.

    modified on Tuesday, July 21, 2009 12:36 PM

    N 1 Reply Last reply
    0
    • J Jordanwb

      I have a class called CardHolder which extends UserControl. I have overrode its OnPaint function like so: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; foreach (Card c in this.Controls) { g.DrawImage(c.Image, c.Location); } } Each image is tied to a Control which has been added to this control. Each image is a partially transparent image which is partially overlaid another image. However, each time the OnPaint function is called, it doesn't clear the Control of what was there before: Good: http://img20.imageshack.us/i/goodw.jpg/[^] Oh dear: http://img24.imageshack.us/i/ohdearz.jpg/[^] I've hooked into the CardHolder's Resize event and call PositionCards in that function to position the Controls, which in turn calls OnPaint behind the scenes. I hope what I'm doing here makes sense to you guys. How do I clear the Control of the previously drawn images? Card extends UserControl as well but is transparent and has no child controls.

      modified on Tuesday, July 21, 2009 12:36 PM

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      How is the OnPaint being called? Call the Refresh() method to make your control invalidate the graphic and repaint itself.


      Panic, Chaos, Destruction. My work here is done.

      J 1 Reply Last reply
      0
      • N Nagy Vilmos

        How is the OnPaint being called? Call the Refresh() method to make your control invalidate the graphic and repaint itself.


        Panic, Chaos, Destruction. My work here is done.

        J Offline
        J Offline
        Jordanwb
        wrote on last edited by
        #3

        I don't know how OnPaint is being called. I'll give Refresh a try. [Edit] Thanks Nagy Vilmos.

        modified on Tuesday, July 21, 2009 12:35 PM

        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