怎样使按钮在窗体里四处游动
就是点不到咯!  private void button1_MouseEnter(object sender, EventArgs e)
        {
            
            Random r = new Random();
            this.button1.Left = r.Next();
            if (button1.Left > this.Left)
            {
                this.button1.Left = r.Next();
            }
            this.button1.Right = r.Next();
           
        }
没有达到我的要求,这个只触发了一次是不是我的事件写错了?
给Right复值是报
错误 1 无法对属性或索引器“System.Windows.Forms.Control.Right”赋值 -- 它是只读的
请写点代码给与支持!
叩谢!

解决方案 »

  1.   

    另外保证Button不跑出窗体的范围....
      

  2.   

    private void button1_MouseEnter(object sender, EventArgs e)
            {
                Random rnd = new Random ();
                button1.Location = new Point(rnd.Next(0, this.Width-button1 .Width ), rnd.Next(0, this.Height-button1 .Height ));
            }这样就行了
      

  3.   

    private void button1_MouseEnter(object sender, EventArgs e)
            {
                
                Random rnd = new Random();
                button1.Left = rnd.Next(0, this.Width - button1.Width);
                button1.Top = rnd.Next(0, this.Height - this.Location.Y);
            }
      

  4.   

    写错了,应该这样:
                Random rnd = new Random();
                button1.Left = rnd.Next(0, this.Width - button1.Width);
                button1.Top = rnd.Next(0,this.ClientRectangle.Height  -button1 .Height );
      

  5.   

    this.ClientRectangle.Height  表示工作区的高度,而不应该用this.Height(Form的高度)..
      

  6.   

    先设置好Button的大小,然后用随机数来设置Button的Location