I want to move a Diamond Shape in the form(for example 2 pixels every 200ms) horizantally.
I used the following code in From_Paint Event.
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Point p1 = new Point(5,0);
Point p2 = new Point(10, 5);
Point p3 = new Point(5, 10);
Point p4 = new Point(0, 5);
Point[] ps = { p1, p2, p3, p4, p1 };
g.DrawLines(Pens.Black, ps);
}
I know how to move a picturebox but how to do with shape.
Thanks,
Ani
You’ll need to track your current location in a form level variable. If you do this, your Form1_Paint event can change the X pixel location each time it draws.
Just add a Timer to your form, and set it’s interval to 200ms. Each 200ms, add 2 to your current X pixel, and invalidate your control (so it redraws).
Edit: Add this to your form:
Then, in your timer_Tick:
Change your paint event to: