一个简单的C#WinForm程序

来源:百度知道 编辑:UC知道 时间:2024/05/09 17:26:38
本人今天在家编写程序时,在一个细节方面忘记了,,就是使用timer控件,让一个图片在Form窗体上面来回的循环的移动..麻烦Csharp语言高手指点,把代码写出来..
例如:
int x=this.pictureBox1.Location.X;
int y=this.pictureBox1.Location.Y;

this.pictureBox1.Location=new Point(int x,int y);

怎么写让pictureBox1移动 做循环的移动即可

声明里面添加
private int x;
private int y;
private static int count = 0;

初始化函数
public Form1()
{
InitializeComponent();
x = this.pictureBox1.Location.X;
y = this.pictureBox1.Location.Y;
}

时钟函数
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (count == 4) count = 0;
int signX,signY = 1;
if (count == 0 || count == 1) signX = 1;
else signX = -1;
if (count == 0 || count == 3) signY = -1;
else signY = 1;
this.Controls.Remove(this.pictureBox1);
pictureBox1.Location = new Point(x+10*signX,y+10*signY);
this.Controls.Add(pictureBox1);
count ++;
}

这里的循环只是一个绕原先点的矩形移动