private void button2_MouseEnter(object sender, EventArgs e) //mouseENter方法,鼠标进入图形部分时 { //根据客户端尺寸变更长短 int x = this.ClientSize.Width - button2.ClientSize.Width; int y = this.ClientSize.Height - button2.ClientSize.Height; //随机数 next() Random rom = new Random(); //point为结构 button2.Location = new Point(rom.Next(0,x),rom.Next(0,y)); }