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. Can I have to PaintEventHandlers in my program

Can I have to PaintEventHandlers in my program

Scheduled Pinned Locked Moved C#
csharpgraphicsvisual-studioannouncement
2 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.
  • L Offline
    L Offline
    laura1316
    wrote on last edited by
    #1

    Hi All, I am trying to draw a rectangle and then draw a circle within the rectangle. At this point I have the rectangle drawing but the circle. The circle within the rectangle is going to move based on motion of the mouse. I am going to try to take the input of the mouse and make those my X and Y coordinates. If anyone has any experience with either have 2 paint event handlers or with having to update the circle depending on location, it would be great! Any sample code and guidance would be greatly appreciated! See below for event handlers. I am developing use C# and Visual Studio 2005. //In constructor, after intialize component call first Paint Event Handler f1_paint. private static void f1_paint(object sender, PaintEventArgs e) { Graphics dc = e.Graphics; Pen p = new Pen(Color.White, 3); dc.DrawRectangle(p, 478, 10, 487, 352); p.Dispose(); } private static void f2_paint(object sender, PaintEventArgs e) { Graphics dc = e.Graphics; Pen o = new Pen(Color.Orange, 5); dc.DrawEllipse(o, 717, 176, 5, 5); o.Dispose(); } //In timer function will take in mouse input and update circle so need to call f2_paint. this.Paint += new PaintEventHandler(f2_paint); Thanks, Laura

    G 1 Reply Last reply
    0
    • L laura1316

      Hi All, I am trying to draw a rectangle and then draw a circle within the rectangle. At this point I have the rectangle drawing but the circle. The circle within the rectangle is going to move based on motion of the mouse. I am going to try to take the input of the mouse and make those my X and Y coordinates. If anyone has any experience with either have 2 paint event handlers or with having to update the circle depending on location, it would be great! Any sample code and guidance would be greatly appreciated! See below for event handlers. I am developing use C# and Visual Studio 2005. //In constructor, after intialize component call first Paint Event Handler f1_paint. private static void f1_paint(object sender, PaintEventArgs e) { Graphics dc = e.Graphics; Pen p = new Pen(Color.White, 3); dc.DrawRectangle(p, 478, 10, 487, 352); p.Dispose(); } private static void f2_paint(object sender, PaintEventArgs e) { Graphics dc = e.Graphics; Pen o = new Pen(Color.Orange, 5); dc.DrawEllipse(o, 717, 176, 5, 5); o.Dispose(); } //In timer function will take in mouse input and update circle so need to call f2_paint. this.Paint += new PaintEventHandler(f2_paint); Thanks, Laura

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

      Don't use a timer. Use the MouseEnter, MouseMove and MouseLeave events to trigger the update the control. Those events give you a MouseEventArgs object that contains the coordinates of the mouse pointer. Store the coordinates in member variables so that you can use them in the paint event. There is no use in having more than one paint event handler for a control. They will just run after each other, so you can just put all the code in the same event handler.

      laura1316 wrote:

      //In timer function will take in mouse input and update circle so need to call f2_paint. this.Paint += new PaintEventHandler(f2_paint);

      That will not call the event handler, it will instead add another event handler to the event. If you do that in a timer event, you soon will have thousands of event handlers in the paint event, each one drawing the same thing on top of the other. When you need the control to be redrawn, just call the Invalidate method of the control. This will cause a paint event.

      --- single minded; short sighted; long gone;

      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