samedi 1 août 2015

Rectangle clockwise movement

I'm trying to make a Windows Forms Application where rectangle moves clockwise. Here's the image. http://ift.tt/1DhNItV

And here is my code.

public partial class Form1 : Form
{
    int x;
    int y;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.FillRectangle(Brushes.Crimson, x, y, 20, 20);
    }

    private void movingTimer_Tick(object sender, EventArgs e)
    {
        while (true)
        {
            if (x < 750)
            {
                x += 5;
            }
            else if (x == 750 && y < 340)
            {
                y += 5;
            }
            break;
        }

        Invalidate();
    }
}

I understand why I can't go further. If I make new if statement with x -= 5 it will be activated simultaneously with the while loop. What I can't understand is how to separate the new commands (x -= 5 and y -= 5) so it would be activated only after my first while loop is finished.

Aucun commentaire:

Enregistrer un commentaire