private void button1_Click(object sender, EventArgs e) { //實現窗體抖動的效果 Point first = this.Location; for (int i = 0; i < 50; i++) { Application.DoEvents(); Random ran = new Random(); Point p = new Point(this.Location.X + ran.Next(10) - 4, this.Location.Y + ran.Next(10) - 4); System.Threading.Thread.Sleep(10);//當前線程再掛起15毫秒 this.Location = p; System.Threading.Thread.Sleep(10);//當前線程再掛起15毫秒 Application.DoEvents(); } this.Location = first; //將窗體還原爲原來的位置 }