成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

C#模擬MSN 窗體抖動

2010-08-28 10:50:44來源:西部e網作者:

窗體抖動是件很有意思的事情,就讓我們看看一起來看看它的原理吧。 
其實是生成隨機數,然后改變Form的左上角的坐標。
我用的是循環來弄得,其實可以用timer來控制.

 我把抖動分成了兩種抖動:
1。 生成隨機數,改變窗體左上角坐標,然后立即把窗體的坐上角坐標還原,繼續循環。
2。 生成隨機數,改變窗體左上角坐標,循環完畢之后,然后立即把窗體的坐上角坐標還原。

核心代碼如下:

//第一種抖動
        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;
        }

Demo下載

原文地址:http://www.cnblogs.com/drizzlecrj/archive/2006/12/20/598697.html

關鍵詞:C#
主站蜘蛛池模板: 榆树市| 法库县| 德昌县| 加查县| 娄烦县| 昌邑市| 武定县| 清涧县| 奉节县| 左贡县| 奇台县| 措美县| 保定市| 固镇县| 西峡县| 博客| 东兴市| 南郑县| 泗水县| 来凤县| 登封市| 拜城县| 来宾市| 辛集市| 南宁市| 霍州市| 奉新县| 富顺县| 新平| 新沂市| 铜梁县| 潮州市| 双柏县| 瑞安市| 襄樊市| 梅州市| 浦县| 昌吉市| 扎赉特旗| 高平市| 施秉县|