转自 http://blog.csdn.net/hui110110/article/details/52431426
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 //导入命名空间 11 using System.Threading; 12 13 14 namespace 窗口抖动 15 { 16 public partial class Form1 : Form 17 { 18 public Form1() 19 { 20 InitializeComponent(); 21 } 22 //x位抖动速度,单位是像素,y为时间间隔,单位是毫秒 23 int x = 5; 24 int y = 10; 25 private void Form1_Load(object sender, EventArgs e) 26 { 27 28 } 29 //添加一个按钮,实现抖动的开始 30 private void button1_Click(object sender, EventArgs e) 31 { 32 button1.Text = "开始抖动"; 33 //死循环实现一直抖动 34 for (; ; ) 35 { 36 this.Left += x; 37 //sleep方法需要导入命名空间System.Threading 38 Thread.Sleep(y); 39 this.Top += x; 40 Thread.Sleep(y); 41 this.Left -= x; 42 Thread.Sleep(y); 43 this.Top -= x; 44 Thread.Sleep(y); 45 } 46 } 47 } 48 }