c#仿QQ顶置自动隐藏的效果
来源:互联网 发布:网络直播概念股 编辑:程序博客网 时间:2024/04/30 01:09
不用说,大家都用过QQ,QQ有个顶置之后自动隐藏的效果。
本人写WinForm的时候需要这样的特效,上网查了一番,然后自己动手实现了。现共享之。
并将此段代码封装成dll文件,在其他项目中用的时候直接引入这个dll就行了。不用每次都写一遍了。
代码如下:
using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.Windows.Forms;namespace ClassLibrary1{ /// <summary> /// 吸附窗体 /// </summary> public class Class1 { private Form frm1; private Timer timer1; /// <summary> /// 吸附窗体 /// </summary> /// <param name="frm">要吸附的窗体</param> /// <param name="timer">计时器对象</param> public Class1(Form frm, Timer timer) { this.frm1 = frm; this.timer1 = timer; this.frm1.LocationChanged += new EventHandler(frm1_LocationChanged); this.frm1.TopMost = true; this.timer1.Enabled = true; this.timer1.Interval = 100; this.timer1.Tick += new EventHandler(timer1_Tick); this.timer1.Start(); } internal AnchorStyles stopAnchor = AnchorStyles.None; /// <summary> /// 计时器控制函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void timer1_Tick(object sender, EventArgs e) { if (frm1.Bounds.Contains(Cursor.Position)) { switch (this.stopAnchor) { case AnchorStyles.Top: frm1.Location = new Point(frm1.Location.X, 0); break; case AnchorStyles.Left: frm1.Location = new Point(0, frm1.Location.Y); break; case AnchorStyles.Right: frm1.Location = new Point(Screen.PrimaryScreen.Bounds.Width - frm1.Width, frm1.Location.Y); break; case AnchorStyles.Bottom: frm1.Location = new Point(frm1.Location.X, Screen.PrimaryScreen.Bounds.Height - frm1.Height); break; } } else { switch (this.stopAnchor) { case AnchorStyles.Top: frm1.Location = new Point(frm1.Location.X, (frm1.Height - 2) * (-1)); break; case AnchorStyles.Left: frm1.Location = new Point((-1) * (frm1.Width - 2), frm1.Location.Y); break; case AnchorStyles.Right: frm1.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, frm1.Location.Y); break; case AnchorStyles.Bottom: frm1.Location = new Point(frm1.Location.X, (Screen.PrimaryScreen.Bounds.Height - 2)); break; } } } private void mStopAnchor() { if (frm1.Top <= 0 && frm1.Left <= 0) { stopAnchor = AnchorStyles.None; } else if (frm1.Top <= 0) { stopAnchor = AnchorStyles.Top; } else if (frm1.Left <= 0) { stopAnchor = AnchorStyles.Left; } else if (frm1.Left >= Screen.PrimaryScreen.Bounds.Width - frm1.Width) { stopAnchor = AnchorStyles.Right; } else if (frm1.Top >= Screen.PrimaryScreen.Bounds.Height - frm1.Height) { stopAnchor = AnchorStyles.Bottom; } else { stopAnchor = AnchorStyles.None; } } /// <summary> /// 窗体移动触发函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frm1_LocationChanged(object sender, EventArgs e) { this.mStopAnchor(); } }}
下面来看在其他项目中调用此dll的方法。
代码很简单,只有一句话。
ClassLibrary1.Class1 class1 = new ClassLibrary1.Class1(this, timer1);
前提是你必须有timer1这个对象。
http://download.csdn.net/detail/crazy1235/4966939
- c#仿QQ顶置自动隐藏的效果
- VC 仿QQ窗口靠边自动收缩隐藏效果
- VC 仿QQ窗口靠边自动收缩隐藏效果
- VC 仿QQ窗口靠边自动收缩隐藏效果
- VC 仿QQ窗口靠边自动收缩隐藏效果
- VC 仿QQ窗口靠边自动收缩隐藏效果
- C#实现仿QQ窗口靠边自动隐藏
- 仿Android QQ实现的QQ顶栏椭圆透明背景移动效果
- MFC仿QQ窗口靠边自动收缩隐藏效果(附源代码)
- 仿QQ的下拉效果
- QQ窗体自动隐藏效果探究
- Android 仿QQ浏览器WebView,滑动隐藏显示ActionBar效果
- android仿QQ列表的效果实现
- 仿QQ写说说效果的实现
- C#仿QQ皮肤—更新DataGridView的鼠标跟随效果
- [VB.NET]请问类似QQ窗体靠边自动隐藏的效果如何实现?????
- 仿QQ圆点拖拽效果
- MFC定时器实现类似QQ桌面自动隐藏效果
- webdriver实现窗口切换
- 杭电2013蟠桃园(水题)
- Raspberry Pi with Node.js and Arduino
- web game server architecture
- jQuery实例集合
- c#仿QQ顶置自动隐藏的效果
- linux0.11 minix1.0文件系统 下篇 根节点的 buffer_head结构,根节点内容
- EJB3.0学习笔记---理解远程调用服务端和本地调用服务端的区别
- 关于隐藏转换的代码
- 临窗静坐
- WiringPi Pins-From Gordon
- Java Socket 3
- 单点登录实现步骤
- Struts2源码阅读(二)_ActionContext及CleanUP Filter .