惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
美团技术团队
D
Docker
WordPress大学
WordPress大学
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
Y
Y Combinator Blog
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
S
SegmentFault 最新的问题
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans

博客园 - 风也无奈

事件学习 信息系统需求分析阶段的实践经验之二---如何有效地获得用户需求【转】 信息系统需求分析阶段的实践经验之一---需求分析概述[转] Lambda表达式【转】 C#委托的介绍(delegate、Action、Func、predicate)【转】 “DllRegisterServer的调用失败”问题解决办法 什么是RFID技术 SQL Server集群服务器的优缺点 asp中的ckEditor的详细配置 UTF8转成GB2312乱码问题解决思路 winform更新程序代码 C#开发串口总结,并提炼串口辅助类到公用类库中 SQLXML]FOR XML语法导出XML的易错之处 C#下载功能代码<转> C#通用类库--数字转为人民币汉字大写表示 - 风也无奈 - 博客园 link和@import的区别 - 风也无奈 - 博客园 C#操作word并格式化 Winform中的DataGridView控件内容自动保存《转载》 SQL中获取一个长字符串中某个字符串出现次数的简单方法
C#通用类库--QQ吸附窗体类
风也无奈 · 2010-12-06 · via 博客园 - 风也无奈

不用多说,贴出代码就能看懂!

 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 

效果:窗体移动到屏幕边缘会自动伸缩,鼠标移上去的话就显示出来!