How to call the paint event handler
-
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 -
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, LauraYou 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 )
-
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, LauraAs 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 callUpdate()
to force the OS to paint your window immediately. /raviThis is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
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 callUpdate()
to force the OS to paint your window immediately. /raviThis is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com