C#- move a shape to a point which is half way from the top of the form

Posted by hello-all on Stack Overflow See other posts from Stack Overflow or by hello-all
Published on 2010-04-24T00:46:06Z Indexed on 2010/04/24 0:53 UTC
Read the original article Hit count: 278

Filed under:
|
|

Hello all,

Here I have to create a diamond using drawlines method and make it move horizontally along a path that is half way from the top of the form.

I created a diamond and it is moving horizontally, but i want it to start moving from a position which is half way from the top of the form.

This is the code to create a diamond, private void Form1_Paint(object sender, PaintEventArgs e) {

        Graphics g = e.Graphics;
        Point p1 = new Point(5+x, 0);
        Point p2 = new Point(10+x, 5);
        Point p3 = new Point(5+x, 10);
        Point p4 = new Point(0+x, 5);
        Point[] ps = { p1, p2, p3, p4, p1 };
        Pen p_yellow = new Pen(Color.Yellow, 5);
        g.DrawLines(p_yellow, ps);
        this.BackColor = System.Drawing.Color.DarkBlue;


    }

I can make it move using the timer and following is the code,

private void timer1_Tick(object sender, EventArgs e) { if (x < 500) x += 2; else timer1.Enabled = false; this.Invalidate();

    }

please tell me how to bring the diamond to a point which is half way from the top of the form?

© Stack Overflow or respective owner

Related posts about c#3.0

Related posts about diamond