//加入以下私有成员变量 private int iSpeed = 2; private int iDistance; private int ixStart= 0; private int iyStart= 0; private int speed; private int x1,y1; private int width1,height1; //双击Form,在其Load事件输入下面的代码: speed=0; System.Drawing.Rectangle ssWorkArea=System.Windows.Forms.Screen.GetWorkingArea(this); //屏幕显示区域 width1=ssWorkArea.Width; //屏幕宽度 height1=ssWorkArea.Height; //屏幕高度 //From的KeyDown,MouseDown,MouseMove事件中都输入以下代码: Application.Exit(); //timer1的Tick事件输入下面代码: //下面设置文本显示框的位置坐标 label1.Location =new System.Drawing.Point(width1-iDistance,label1.Location.Y); label1.Visible=true; //设置为可见 iDistance+=iSpeed; if(label1.Location.X<=-(label1.Width)) { iDistance=0; if(label1.Location.Y==0) label1.Location=new System.Drawing.Point(label1.Location.X,height1/2); else if(label1.Location.Y==height1/2) label1.Location=new System.Drawing.Point(label1.Location.X,height1-label1.Height); else label1.Location=new System.Drawing.Point(label1.Location.X,0); } //下面是计算图片框移动坐标 speed++; if(speed<=2*height1) { x1=System.Math.Abs(width1-speed); y1=System.Math.Abs(height1-speed); } else if(speed>2*height1 && speed<=2*width1) { x1=System.Math.Abs(width1-speed); y1=System.Math.Abs(height1-(speed-speed/height1*height1)); } else if(speed>2*width1 &&speed<=3*height1) { x1=System.Math.Abs(width1-(speed-speed/width1*width1)); y1=System.Math.Abs(height1-(speed-speed/height1*height1)); } else if(speed>3*height1 && speed<4*height1) { x1=System.Math.Abs(width1-(speed-speed/width1*width1)); y1=System.Math.Abs(speed-speed/height1*height1); } else if(speed>=4*height1 && speed<5*height1) { x1=System.Math.Abs(speed-speed/width1*width1); y1=System.Math.Abs(height1-(speed-speed/height1*height1)); } else if(speed>=5*height1 && speed<4*width1) { x1=System.Math.Abs(speed-speed/width1*width1); y1=System.Math.Abs(speed-speed/height1*height1); } else if(speed>=4*width1 && speed<6*height1) { x1=System.Math.Abs(width1-(speed-speed/width1*width1)); y1=System.Math.Abs(speed-speed/height1*height1); } else if(speed>=6*height1 && speed<5*width1) { x1=System.Math.Abs(width1-(speed-speed/width1*width1)); y1=System.Math.Abs(height1-(speed-speed/height1*height1)); } else if(speed>=5*width1 && speed<7*height1) { x1=System.Math.Abs(speed-speed/width1*width1); y1=System.Math.Abs(height1-(speed-speed/height1*height1)); } else if(speed>=7*height1 && speed<6*width1) { x1=System.Math.Abs(speed-speed/width1*width1); y1=System.Math.Abs(speed-speed/height1*height1); } if(speed==6*width1) speed=0; pictureBox1.Location=new System.Drawing.Point(x1,y1); |