通过按钮事件实现窗体在水平方向、垂直方向、对角方向的移动

解决方案 »

  1.   

    按纽事件里添加 窗体.Location.x ++,或者 窗体.Location.y++;
      

  2.   

    上this.Top--;
    下this.Top--;
    左 this.Left--;
    右 this.Left++;
      

  3.   


    this.Location = new Point(this.Location.X + 1, this.Location.Y); //从左到右
    this.Location = new Point(this.Location.X - 1, this.Location.Y); //从右到左this.Location = new Point(this.Location.X, this.Location.Y + 1); //从上到下
    this.Location = new Point(this.Location.X, this.Location.Y - 1); //从下到上this.Location = new Point(this.Location.X + 1, this.Location.Y + 1); //从左上到右下
    this.Location = new Point(this.Location.X + 1, this.Location.Y + 1); //从右下到左上
    // 其他方向,照此发挥this.Location.X+this.Width == 屏幕宽度 这时 this.Location.X =0 //其他类似处理
      

  4.   

    加定时器,在Tick事件中执行移动操作,用按扭控制 Timer.Start() Timer.Stop
      

  5.   

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private Timer t = new Timer();
            private Timer t1 = new Timer();        private void Form1_Load(object sender, EventArgs e)
            {
                t.Interval = 10;
                t.Tick += new EventHandler(button4_Click);//到达时间的时候执行事件; 
                t1.Interval = 10;
                t1.Tick += new EventHandler(button5_Click);//到达时间的时候执行事件; 
               
               
            }       //左移
            private void button4_Click(object sender, EventArgs e)
            {
                Rectangle rect = new Rectangle();
                rect = Screen.GetWorkingArea(this);
                t1.Stop();
                t.Start();
                  
                    this.Left--;
                    if (this.Left < 0)
                    {
                        this.Left = rect.Width;
                    }
             
            }
           //右移
            private void button5_Click(object sender, EventArgs e)
            {
                 Rectangle rect = new Rectangle();
                rect = Screen.GetWorkingArea(this);
                t.Stop();
                t1.Start();            this.Left++;
                if (this.Left >= rect.Width)
                {
                    this.Left = 0;
                }
        }
      

  6.   

    这个问题简单啊,你用个timer的ticker来控制他,同时判断他到了什么位置应该做什么动作,不如到了边界又反弹会来呀,还是怎么的,而你的按钮空间是需要控制timer的enable属性就行了。
      

  7.   

    嗯。建议使用Timer来实现,如果使用代码直接实现,估计CPU占用比较大
      

  8.   

    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width   
    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
      

  9.   

     this.Location.X=0; 这句反不回去啊
      

  10.   


    屏幕
    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width   
    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
     
    工作区 
    C# codeScreen.PrimaryScreen.WorkingArea.Height;
    Screen.PrimaryScreen.WorkingArea.Width;
    this.Location.X=0;
    改成
    this.Location = new Point(0, this.Location.Y); //从左到右
      

  11.   


    this.Location = new Point(this.Location.X + 5, this.Location.Y);
                if (this.Location.X + this.Width == Screen.PrimaryScreen.Bounds.Width)
                    this.Location = new Point(0, this.Location.Y); 大哥  这样还是不行啊  移出窗体后还是无法从屏幕的左边出来
      

  12.   

    改为:this.Location = new Point(this.Location.X + 5, this.Location.Y);
    if (this.Location.X > Screen.PrimaryScreen.Bounds.Width)
    this.Location = new Point(0, this.Location.Y);