C#模擬MSN窗體抖動的實現(xiàn)代碼
基于C#實現(xiàn)窗體的抖動是件很有意思的事情,原理并不難,其實是生成隨機數(shù),然后改變Form的左上角的坐標即可。
這里用的是循環(huán)來實現(xiàn)的,其實還可以用timer來控制.
我把抖動分成了兩種抖動:
1.生成隨機數(shù),改變窗體左上角坐標,然后立即把窗體的坐上角坐標還原,繼續(xù)循環(huán)。
2.生成隨機數(shù),改變窗體左上角坐標,循環(huán)完畢之后,然后立即把窗體的坐上角坐標還原。
主要功能代碼如下:
//第一種抖動 private void button1_Click(object sender, EventArgs e) { int recordx = this.Left; //保存原來窗體的左上角的x坐標 int recordy = this.Top; //保存原來窗體的左上角的y坐標 Random random = new Random(); for (int i = 0; i < 100; i++) { int x = random.Next(rand); int y = random.Next(rand); if (x % 2 == 0) { this.Left = this.Left + x; } else { this.Left = this.Left - x; } if (y % 2 == 0) { this.Top = this.Top + y; } else { this.Top = this.Top - y; } this.Left = recordx; //還原原始窗體的左上角的x坐標 this.Top = recordy; //還原原始窗體的左上角的y坐標 } } //第二種抖動 private void button2_Click(object sender, EventArgs e) { int recordx = this.Left; int recordy = this.Top; Random random = new Random(); for (int i = 0; i < 50; i++) { int x = random.Next(rand); int y = random.Next(rand); if (x % 2 == 0) { this.Left = this.Left + x; } else { this.Left = this.Left - x; } if (y % 2 == 0) { this.Top = this.Top + y; } else { this.Top = this.Top - y; } System.Threading.Thread.Sleep(1); } this.Left = recordx; this.Top = recordy; }
相關(guān)文章
C# datagridview、datagrid、GridControl增加行號代碼解析
今天這篇文章小編就來給大家分享關(guān)于C# datagridview、datagrid、GridControl增加行號的介紹,主要包括WinForm中datagridview增加行號、WPF中datagrid增加行號、WPF dev控件GridControl增加行號三個內(nèi)容,感興趣等我小伙伴可以參考一下2021-10-10npoi2.0將datatable對象轉(zhuǎn)換為excel2007示例
這篇文章主要介紹了npoi2.0將datatable對象轉(zhuǎn)換為excel2007示例的相關(guān)資料2014-04-04基于WebRequest.RegisterPrefix的使用詳解
本篇文章對WebRequest.RegisterPrefix的使用進行了詳細的分析介紹,需要的朋友參考下2013-05-05