C#實現QQ視窗抖動效果
阿新 • • 發佈:2020-11-25
本文例項為大家分享了C#實現QQ視窗抖動效果的具體程式碼,供大家參考,具體內容如下
實現介面:
1. 兩個textbook和兩個Button
2. NotifyIcon控制元件是實現托盤
實現程式碼:
private void Form1_Load(object sender,EventArgs e) { this.Text = "聊天視窗"; button1.Text = "抖動"; button2.Text = "傳送"; this.AutoSizeMode = AutoSizeMode.GrowAndShrink; textBox1.ReadOnly = true; //獲取焦點在textBox2上面用來發送訊息 textBox2.TabIndex = 0; x = this.Left; y = this.Top; //設定視窗中某個按鈕可以同Enter鍵進行控制效果 this.AcceptButton = button2; } int x,y; int t=30,space = 3; private void Button1_Click(object sender,EventArgs e) { for (int i=0;i<2 ;i++ ) { this.Location = new Point(x - space,y); Thread.Sleep(t); this.Location = new Point(x - space,y - space); Thread.Sleep(t); this.Location = new Point(x,y - space); Thread.Sleep(t); this.Location = new Point(x + space,y); Thread.Sleep(t); this.Location = new Point(x + space,y + space); Thread.Sleep(t); this.Location = new Point(x,y + space); Thread.Sleep(t); this.Location = new Point(x - space,y); Thread.Sleep(t); this.Location = new Point(x,y); } } private void Button2_Click(object sender,EventArgs e) { if (String.IsNullOrWhiteSpace(textBox2.Text)==false) { textBox1.Text += DateTime.Now + "\r\n" + textBox2.Text + "\r\n"; textBox2.Text = ""; } } //resize視窗尺寸變動 private void Form1_Resize(object sender,EventArgs e) { //最小化到系統托盤 if (this.WindowState==FormWindowState.Minimized) { this.ShowInTaskba=false; } } //Close關閉視窗 private void NotifyIcon1_MouseDoubleClick(object sender,MouseEventArgs e) { this.ShowInTaskba=true; this.WindowState=FormWindowState.Normal; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。