C#通用類庫–QQ吸附表單類

來源:互聯網
上載者:User

不用多說,貼出代碼就能看懂!

 1 //類名:EcanQQ
 2 //作用:QQ吸附表單
 3 //作者:劉典武
 4 //時間:2010-12-01
 5 //用法:添加timer控制項,enable設定為true,執行個體化類EcanQQ qqfrm = new EcanQQ();timer1_Tick時間調用qqfrm.hide_show(this, ref height, timer1);     
 6 
 7 using System;
 8 using System.Collections.Generic;
 9 using System.Text;
10 using System.Windows.Forms;
11 
12 namespace Ecan
13 {
14     public class EcanQQ
15     {
16         /// <summary>
17         /// QQ吸附表單
18         /// </summary>
19         /// <param name="frm">要吸附邊緣的表單</param>
20         /// <param name="frmHeight">表單的高度</param>
21         /// <param name="timer">定時器控制項</param>
22         //用法:在對應表單timer控制項的Tick事件中寫代碼 int height = this.Height; EcanQQ.hide_show(this, ref height, timer1);
23         
24         public void hide_show(Form frm, ref int frmHeight, Timer timer)
25         {
26             if (frm.WindowState != FormWindowState.Minimized)
27             {
28                 timer.Interval = 100;                
29                 if (Cursor.Position.X > frm.Left - 1 && Cursor.Position.X < frm.Right && Cursor.Position.Y > frm.Top - 1 && Cursor.Position.Y < frm.Bottom)
30                 {
31                     if (frm.Top <= 0 && frm.Left > 5 && frm.Left < Screen.PrimaryScreen.WorkingArea.Width - frm.Width)
32                     {
33                         frm.Top = 0;
34                     }
35                     else if (frm.Left <= 0)
36                     {
37                         frm.Left = 0;
38                     }
39                     else if (frm.Left + frm.Width > Screen.PrimaryScreen.WorkingArea.Width)
40                     {
41                         frm.Left = Screen.PrimaryScreen.WorkingArea.Width - frm.Width;
42                     }
43                     else
44                     {
45                         if (frmHeight > 0)
46                         {
47                             frm.Height = frmHeight;
48                             frmHeight = 0;
49                         }
50                     }
51                 }
52                 else
53                 {
54                     if (frmHeight < 1)
55                     {
56                         frmHeight = frm.Height;
57                     }
58                     if (frm.Top <= 4 && frm.Left > 5 && frm.Left < Screen.PrimaryScreen.WorkingArea.Width - frm.Width)
59                     {
60                         frm.Top = 3 - frm.Height;
61                         if (frm.Left <= 4)
62                         {
63                             frm.Left = -5;
64                         }
65                         else if (frm.Left + frm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
66                         {
67                             frm.Left = Screen.PrimaryScreen.WorkingArea.Width - frm.Width + 5;
68                         }
69                     }
70                     else if (frm.Left <= 4)
71                     {
72                         frm.Left = 3 - frm.Width;
73                     }
74                     else if (frm.Left + frm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
75                     {
76                         frm.Left = Screen.PrimaryScreen.WorkingArea.Width - 3;
77                     }
78                 }
79             }
80         }
81     }
82 }
83 

效果:表單移動到螢幕邊緣會自動調整,滑鼠移上去的話就顯示出來!

 

一個C#資源分享平台,專業分享學習高品質代碼,每周期布置學習任務,激發學習C#興趣!(QQ群:128874886)
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.