QQ停靠方法3:
QQ停靠方法3:
相对来说也是比较简单,首先右键解决方案添加类EcanQQ ,其次在要停靠的窗体上添加timer控件,enable设置为true,timer控件的Tick事件中写如下代码
EcanQQ qqfrm = new EcanQQ();//实例化类EcanQQ
int height = this.Height;
EcanQQ.hide_show(this, ref height, timer1);//timer1_Tick时间调用函数qqfrm.hide_show();
这样就可以实现停靠了。
EcanQQ 类的代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace QQ停靠4
{
class EcanQQ
{
/// <summary>
/// QQ吸附窗体
/// </summary>
/// <param name="frm">要吸附边缘的窗体</param>
/// <param name="frmHeight">窗体的高度</param>
/// <param name="timer">定时器控件</param>
//用法:在对应窗体timer控件的Tick事件中写代码 int height = this.Height; EcanQQ.hide_show(this, ref height, timer1);
public void hide_show(Form frm, ref int frmHeight, Timer timer)
{
if (frm.WindowState != FormWindowState.Minimized)
{
timer.Interval = 100;
if (Cursor.Position.X > frm.Left - 1 && Cursor.Position.X < frm.Right && Cursor.Position.Y > frm.Top - 1 && Cursor.Position.Y < frm.Bottom)
{
if (frm.Top <= 0 && frm.Left > 5 && frm.Left < Screen.PrimaryScreen.WorkingArea.Width - frm.Width)
{
frm.Top = 0;
}
else if (frm.Left <= 0)
{
frm.Left = 0;
}
else if (frm.Left + frm.Width > Screen.PrimaryScreen.WorkingArea.Width)
{
frm.Left = Screen.PrimaryScreen.WorkingArea.Width - frm.Width;
}
else
{
if (frmHeight > 0)
{
frm.Height = frmHeight;
frmHeight = 0;
}
}
}
else
{
if (frmHeight < 1)
{
frmHeight = frm.Height;
}
if (frm.Top <= 4 && frm.Left > 5 && frm.Left < Screen.PrimaryScreen.WorkingArea.Width - frm.Width)
{
frm.Top = 3 - frm.Height;
if (frm.Left <= 4)
{
frm.Left = -5;
}
else if (frm.Left + frm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
{
frm.Left = Screen.PrimaryScreen.WorkingArea.Width - frm.Width + 5;
}
}
else if (frm.Left <= 4)
{
frm.Left = 3 - frm.Width;
}
else if (frm.Left + frm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
{
frm.Left = Screen.PrimaryScreen.WorkingArea.Width - 3;
}
}
}
}
}
}
浙公网安备 33010602011771号