int x =10;int y =10;privatevoidtimer1_Tick(object sender,EventArgs e){this.Left += x;this.Top += y;// this.Top=this.Top+y if(this.Top+this.Height>=Screen.PrimaryScreen.WorkingArea.Height ||this.Top<=0)//移动的距离+控件的高度碰到窗口顶部或者底部{
y *=-1;// y=y*-1}if(this.Left +this.Width >= Screen.PrimaryScreen.WorkingArea.Width ||this.Left <=0)//移动的距离+控件的宽度碰到窗口左端或者右端{
x *=-1;//x=x*-1}}