c#如何实现类似qq一样的窗口震动?
c#如何实现类似qq一样的窗口震动?c#如何实现类似qq一样的窗口震动?
c#如何实现类似qq一样的窗口震动?
要有详细的代码和控件的说明哦,谢了的,很重要的哦!!
追问:老实说,我刚看过这个代码了的,你再加点代码注释吧!!
c#如何实现类似qq一样的窗口震动?c#如何实现类似qq一样的窗口震动?
c#如何实现类似qq一样的窗口震动?
要有详细的代码和控件的说明哦,谢了的,很重要的哦!!
追问:老实说,我刚看过这个代码了的,你再加点代码注释吧!!
答案:using System;
using System.Windows.Forms;
using System.Drawing;
class myform : Form {
Button b;
public myform()
{
b = new Button();
b.Text = "点击试试??";
Controls.Add(b);
b.Click += new EventHandler(b_Click);
}
public void b_Click(object sender, EventArgs e)
{
int ex = 30;
for (int i = 0; i < 52; ++i) {
int x = this.Location.X;
int y = this.Location.Y;
switch (i % 4) {
case 0: x += ex; break;
case 1: y += ex; break;
case 2: x -= ex; break;
case 3: y -= ex; break;
}
Location = new Point(x, y);
System.Threading.Thread.Sleep(10);
}
}
}
public class test {
static void Main()
{
myform m = new myform();
Application.Run(m);
}
}
int index = 0;
int count = 0;
//成员变量 index代表当前位置,count循环次数
——————————————————————————————
private void button_DouDong_Click(object sender, EventArgs e)
{
index = 0;
count = 0;
timer_Doudong.Start();
//点击 抖动 事件,触发事件
}
——————————————————————————————
private void timer_Doudong_Tick(object sender, EventArgs e)
{
//此为 timer控件,默认interval=50毫秒
switch (index)
{
case 0:
this.Location = new Point(this.Location.X, this.Location.Y + 3);
index++;
break;
case 1:
this.Location = new Point(this.Location.X + 3, this.Location.Y);
index++;
break;
case 2:
this.Location = new Point(this.Location.X - 3, this.Location.Y);
index++;
break;
case 3:
this.Location = new Point(this.Location.X, this.Location.Y - 3);
index = 0;
count++;
if (count == 4)
{
timer_Doudong.Stop();
}
break;
}
}
//你觉得呢,比不上腾讯的抖动优美,不过基本的思想已经出来,楼主可以根据此修改一下更为美化