效果應該都知道, 這邊就直接貼程式碼囉~
private void crazyShake()
{
// 設定震動範圍
Int32 offset = 10;
// 先記錄目前的位置
Point ori = this.Location;
// 取得亂數表
Random r = new Random(DateTime.Now.Millisecond);
// 隨機變換目前視窗位置 (以原始座標為原點)
for (int i = 0; i < 30; i++)
{
Point tmp = new Point(ori.X + r.Next(-offset, offset), ori.Y + r.Next(-offset, offset));
this.Location = tmp;
Thread.Sleep(20);
}
// 震動效果結束 還原座標位置
this.Location = ori;
}
短短幾行就能達到這樣的效果, 不難吧
好啦~ 其實我有保留~ 沒那麼簡單
自己去發現問題吧 :D
全站熱搜