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. How to call the paint event handler

How to call the paint event handler

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

    Hi All, I am tring to call a paint event with a timer so that the points change depending on the location. I am going to have a for loop that incrementally changes the X location. So I am not sure quite how to do this. This is my paint code: private void PictureBox1_Paint(object sender, PaintEventArgs e) { Filtered_Tilt f = new Filtered_Tilt(); Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(f.front, ballsize); Pen p = new Pen(Color.Blue, 4); front.X = f.x; front.Y = f.y; g.DrawEllipse(p, r); } I have a timer function that updates the X I then need to call the paint event to refresh the ellipse on the form. How do I do this? x is a global int variable. front is a global point. ***** GLobal Variable***** public int x, y; public Point front; private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < pictureBox1.Width; i++) { x = i; } // How to call the paint event handler to pass it the new x value? } Thanks, Laura

    C R 2 Replies Last reply
    0
    • L laura1316

      Hi All, I am tring to call a paint event with a timer so that the points change depending on the location. I am going to have a for loop that incrementally changes the X location. So I am not sure quite how to do this. This is my paint code: private void PictureBox1_Paint(object sender, PaintEventArgs e) { Filtered_Tilt f = new Filtered_Tilt(); Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(f.front, ballsize); Pen p = new Pen(Color.Blue, 4); front.X = f.x; front.Y = f.y; g.DrawEllipse(p, r); } I have a timer function that updates the X I then need to call the paint event to refresh the ellipse on the form. How do I do this? x is a global int variable. front is a global point. ***** GLobal Variable***** public int x, y; public Point front; private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < pictureBox1.Width; i++) { x = i; } // How to call the paint event handler to pass it the new x value? } Thanks, Laura

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

      You can never call the Paint event directly. Instead, you force it by doing this: Invalidate();

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • L laura1316

        Hi All, I am tring to call a paint event with a timer so that the points change depending on the location. I am going to have a for loop that incrementally changes the X location. So I am not sure quite how to do this. This is my paint code: private void PictureBox1_Paint(object sender, PaintEventArgs e) { Filtered_Tilt f = new Filtered_Tilt(); Graphics g = e.Graphics; Size ballsize = new Size(30, 30); Rectangle r = new Rectangle(f.front, ballsize); Pen p = new Pen(Color.Blue, 4); front.X = f.x; front.Y = f.y; g.DrawEllipse(p, r); } I have a timer function that updates the X I then need to call the paint event to refresh the ellipse on the form. How do I do this? x is a global int variable. front is a global point. ***** GLobal Variable***** public int x, y; public Point front; private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < pictureBox1.Width; i++) { x = i; } // How to call the paint event handler to pass it the new x value? } Thanks, Laura

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        As CG has pointed out, you call Invalidate() to invalidate the window, which will cause the OS to eventually call your paint handler. In addition, you can call Update() to force the OS to paint your window immediately. /ravi

        This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

        L 1 Reply Last reply
        0
        • R Ravi Bhavnani

          As CG has pointed out, you call Invalidate() to invalidate the window, which will cause the OS to eventually call your paint handler. In addition, you can call Update() to force the OS to paint your window immediately. /ravi

          This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          L Offline
          L Offline
          laura1316
          wrote on last edited by
          #4

          Thanks so much that worked!:-D

          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