C# 如何使用c在visual studio中使用循环使对象上下左右移动#

C# 如何使用c在visual studio中使用循环使对象上下左右移动#,c#,animation,sprite,C#,Animation,Sprite,我可以使用for循环使图片框中的图片左右移动,这就是我的代码 private void xAnimeTimer_Tick(object sender, EventArgs e) { int count; this.xAnimeTimer.Stop(); // start point end point speed for (count = 0; count <= 1350; count+=2)

我可以使用for循环使图片框中的图片左右移动,这就是我的代码

private void xAnimeTimer_Tick(object sender, EventArgs e)
    {
        int count;


        this.xAnimeTimer.Stop();



        //   start point   end point   speed
        for (count = 0; count <= 1350; count+=2)
        {
            this.xAnimePictureBox.Left = count;


        }

        for (count = 0; count <= 810; count += 2)
        {
            this.xAnimePictureBox.Top = count;


        }
private void xAnimeTimer_Tick(对象发送方,事件参数e)
{
整数计数;
this.xAnimeTimer.Stop();
//起点终点速度

对于(count=0;count您的this.xAnimePictureBox是否已放置在中心位置?如果已放置,则否定您的计数将为您提供镜像方向(右下为左上)

如果不是,则将你的this.xAnimePictureBox移到中间,并否定你的.Top和.Left

通过中心,我假设1350是宽度,810是高度? 中心将是1350/2810/2 将图片盒的中心与画布的中心配对(或固定图片盒的任何东西),左=1350/2-(图片盒宽度/2),右=810/2-(图片盒高度/2)。

颠倒您拥有的:

   this.xAnimeTimer.Stop();



    //   start point   end point   speed
    for (count = 1350; count >= 0; count-=2)
    {
        this.xAnimePictureBox.Left = count;


    }

    for (count = 810; count >= 0; count -= 2)
    {
        this.xAnimePictureBox.Top = count;


    }

原点(0,0)因为屏幕图形是绘图区域的左上角。因此,较小的顶部值将使项目在屏幕上向上移动,直到达到0为止,然后项目将从屏幕顶部移动。另一方面,较小的左侧值将使项目向左移动。

感谢您的帮助,响应速度非常快。我知道了I’’为了完成这项课堂作业,我们花了一整天的时间来学习。再次感谢。