Focus on my subject! Powered by HendyZhu

永久域名:http://hendy.cnblogs.com

导航

C#实现窗体抖动功能

QQ2009版和2010版都有窗体抖动的功能

其实这个功能在C#中也可以实现。

改变窗体的位置,间隔一定时间,但必须是围绕起始位置改变窗体位置,否则就只是窗体的移动。

 

代码
 1 using System;
 2 using System.Drawing;
 3 using System.Windows.Forms;
 4 
 5 namespace HendyZhuBlog
 6 {
 7     public partial class Form1 : Form
 8     {
 9         public Form1()
10         {
11             InitializeComponent();
12         }
13 
14         private void button1_Click(object sender, EventArgs e)
15         {
16             Random ran = new Random((int)DateTime.Now.Ticks);
17             Point point = this.Location;
18             for (int i = 0; i < 40; i++)
19             {
20                 this.Location = new Point(point.X + ran.Next(8- 4, point.Y + ran.Next(8- 4);
21                 System.Threading.Thread.Sleep(10);
22                 this.Location = point;
23                 System.Threading.Thread.Sleep(10);
24             }
25         }
26     }
27 }

 

 

 

posted on 2010-06-23 00:13  Hendy Chu  阅读(789)  评论(0编辑  收藏  举报