以前用vb 作过一个小程序 就是在窗体上 有个button 当鼠标移到button 上时 button 会随即移动到别的地方 (就是让鼠标永远也点不到button)。在c#里试过 button.move 了不过 不行 。。刚刚接触 c# 那位 能给指点一下 先谢了。。

解决方案 »

  1.   

    试试MouseEnter事件,直接修改button.Location
      

  2.   

    MouseEnter事件,表示鼠标移到按钮上时发生事件private void button1_MouseEnter(object sender, EventArgs e)
    {
         Random r = new Random();
         this.button1.Left = r.Next(this.Width);
         this.button1.Top = r.Next(this.Height);
    }
      

  3.   

    参考如下代码:
    private Point[] btnLocations = { new Point(10, 10), 
        new Point(100, 100), new Point(150, 20) };
    private int index = 0;private void Form1_Load(object sender, EventArgs e)
    {
        button1.Location = btnLocations[index];
    }private void button1_MouseEnter(object sender, EventArgs e)
    {
        index = (index + 1) % btnLocations.Length;
        button1.Location = btnLocations[index];           
    }
      

  4.   

    解决了 谢谢 几位 用buton.left 和button.top 就可以重新定义button 的位置了  谢谢大家帮忙 ^_^