using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace floatingForm
{
    public partial class FloatingForm : Form
    {
        public FloatingForm()
        {
            InitializeComponent();
        }        private void timer1_Tick(object sender, EventArgs e)
        {
            Point p = new Point(0,370);
            //p.X = this .DesktopLocation .X ;
            while (this .DesktopLocation .X  <=0)
            {
                for (int i = 0; i < this.DesktopBounds.Width; i++)
                {
                    Point p1 = new Point(this.DesktopLocation.X + 1, this.DesktopLocation.Y);
                    this.DesktopLocation = p1;
                    //p = p1;
                }
                if (this.DesktopLocation.X == this.DesktopBounds.Width)
                {
                    for (int i = this.DesktopBounds.Width; i > 0; i++)
                    {
                        //Point p2 = new Point(20, 370);
                        //this.DesktopLocation = p2;                        Point p2 = new Point(this.DesktopLocation.X - 1, this.DesktopLocation.Y);                        this.DesktopLocation = p2;
                    }
                    
                }                this.DesktopLocation = p;            }
          
                     }        private void FloatingForm_Load(object sender, EventArgs e)
        {
            Point p = new Point(0, 370);
            this.DesktopLocation = p;
        }      
    }
}
在程序运行时,只能够来回一次,我想做的是能够不断自动来回的,想了好半天还是没头绪,小弟我是初学者,希望有哪位大大能够帮忙解答一下,非常感谢!!!

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace FloatForm
    {
        public partial class Form1 : Form
        {
            int x;
            int y;
            int incre_x;
            int incre_y;
            public Form1()
            {
                InitializeComponent();
                x = 0; 
                y = 370;
                incre_x = 10;
                incre_y = 10;
                this.Location = new Point(x, y);
                timer1.Start();
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                x += incre_x;
                y += incre_y;
                if (x > 1024 || x < 0)
                    incre_x *= -1;
                if (y > 768 || y < 0)
                    incre_y *= -1;
                this.Location = new Point(x, y);
            }
        }
    }
      

  2.   

    设置一下x,y坐标,分别判断xy的边界值,然后写个for语句实现x++,Y++,X--,y--就行了