C#实现仿QQ窗口靠边自动隐藏
2014-05-10 21:05
1031 查看
今晚做网络通讯的实验,想实现下类似QQ滴窗口靠近屏幕上方自动隐藏,上网搜了下代码,发现这个比较简单,而且又很好的实现了所需功能,特记录如下,主要用了三个计时器来实现,开始时设置计时器1启用,计时器2 和计时器3禁用,代码很简单但很强大:
/* 其中全局变量:private bool isHiding = false;
private int startY = 0;*/
/// <summary>
/// 监控鼠标和窗口位置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
int mouse_x = Cursor.Position.X,mouse_y = Cursor.Position.Y;/*鼠标当前位置*/
int window_x = this.Location.X,window_y = this.Location.Y;/*窗体当前位置*/
int window_width = this.Size.Width,window_height = this.Size.Height;/*窗体宽度高度*/
if (isHiding == false && window_y == 0)/*如果窗体靠近上边缘且未隐藏*/
{
if (window_x - mouse_x > 10 || mouse_x - window_x - window_width > 10
|| mouse_y - window_y - window_height > 10)/*如果鼠标位于窗体之外*/
{
timer1.Enabled = false;
timer2.Enabled = true;
}
}
if (isHiding == true && mouse_y <= 1 && mouse_x > window_x && /*窗体已隐藏且鼠标位于窗体范围内*/
mouse_x < window_x + window_width)
{
timer1.Enabled = false;
timer3.Enabled = true;
}
}
/// <summary>
/// 隐藏界面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer2_Tick(object sender, EventArgs e)
{
int window_height = this.Size.Height;//窗体高度
startY += window_height / 10;
if (startY < window_height)
{
/*产生连续滴效果*/
this.Location = new Point(this.Location.X, -startY);
}
else
{
this.Location = new Point(this.Location.X, 1 - window_height);/*设置窗体在屏幕上的显示的高度为1像素*/
isHiding = true;
timer2.Enabled = false;
timer1.Enabled = true;
}
}
/// <summary>
/// 显示界面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer3_Tick(object sender, EventArgs e)
{
int window_height = this.Size.Height;//窗体高度
startY -= window_height / 10;
if (startY > 0)
{
this.Location = new Point(this.Location.X, -startY);
}
else
{
this.Location = new Point(this.Location.X, 0);/*窗体完全在屏幕上显示*/
isHiding = false;
timer3.Enabled = false;
timer1.Enabled = true;
}
}
如果你需要完整实现源代码,请移步:http://download.csdn.net/detail/lgd_yyf/4434075#comment这个是原作者滴代码,
另外,如果有需要,也可以参考这篇文章:http://blog.csdn.net/crystal_lz/article/details/8170491(关于C#绘制qq好友列表控件),比较好的绘制了QQ好友列表的控件,可以直接引用作者的dll文件O(∩_∩)O哈哈~
/* 其中全局变量:private bool isHiding = false;
private int startY = 0;*/
/// <summary>
/// 监控鼠标和窗口位置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
int mouse_x = Cursor.Position.X,mouse_y = Cursor.Position.Y;/*鼠标当前位置*/
int window_x = this.Location.X,window_y = this.Location.Y;/*窗体当前位置*/
int window_width = this.Size.Width,window_height = this.Size.Height;/*窗体宽度高度*/
if (isHiding == false && window_y == 0)/*如果窗体靠近上边缘且未隐藏*/
{
if (window_x - mouse_x > 10 || mouse_x - window_x - window_width > 10
|| mouse_y - window_y - window_height > 10)/*如果鼠标位于窗体之外*/
{
timer1.Enabled = false;
timer2.Enabled = true;
}
}
if (isHiding == true && mouse_y <= 1 && mouse_x > window_x && /*窗体已隐藏且鼠标位于窗体范围内*/
mouse_x < window_x + window_width)
{
timer1.Enabled = false;
timer3.Enabled = true;
}
}
/// <summary>
/// 隐藏界面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer2_Tick(object sender, EventArgs e)
{
int window_height = this.Size.Height;//窗体高度
startY += window_height / 10;
if (startY < window_height)
{
/*产生连续滴效果*/
this.Location = new Point(this.Location.X, -startY);
}
else
{
this.Location = new Point(this.Location.X, 1 - window_height);/*设置窗体在屏幕上的显示的高度为1像素*/
isHiding = true;
timer2.Enabled = false;
timer1.Enabled = true;
}
}
/// <summary>
/// 显示界面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer3_Tick(object sender, EventArgs e)
{
int window_height = this.Size.Height;//窗体高度
startY -= window_height / 10;
if (startY > 0)
{
this.Location = new Point(this.Location.X, -startY);
}
else
{
this.Location = new Point(this.Location.X, 0);/*窗体完全在屏幕上显示*/
isHiding = false;
timer3.Enabled = false;
timer1.Enabled = true;
}
}
如果你需要完整实现源代码,请移步:http://download.csdn.net/detail/lgd_yyf/4434075#comment这个是原作者滴代码,
另外,如果有需要,也可以参考这篇文章:http://blog.csdn.net/crystal_lz/article/details/8170491(关于C#绘制qq好友列表控件),比较好的绘制了QQ好友列表的控件,可以直接引用作者的dll文件O(∩_∩)O哈哈~
相关文章推荐
- C# 实现QQ那样靠边停靠自动隐藏
- 浅谈如何利用PB实现仿QQ自动显示/隐藏窗口(原创)
- c# winform 窗口实现自动隐藏
- C#实现QQ靠边隐藏的功能
- C#实现相似QQ的隐藏浮动窗口、消息闪动
- VC 仿QQ窗口靠边自动收缩隐藏效果
- MFC仿QQ窗口靠边自动收缩隐藏效果(附源代码)
- VC 仿QQ窗口靠边自动收缩隐藏效果
- VC 仿QQ窗口靠边自动收缩隐藏效果
- [VB.NET]请问类似QQ窗体靠边自动隐藏的效果如何实现?????
- VC 仿QQ窗口靠边自动收缩隐藏效果
- Java实现窗体隐藏,功能类似于QQ窗口自动隐藏
- VC 仿QQ窗口靠边自动收缩隐藏效果
- C#实现QQ靠边隐藏的功能
- C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm
- C#实现smartQQ 扫码登录分析自动收发消息
- c# 实现窗体拖到屏幕边缘自动隐藏
- C#实现 类似 qq、 msn 的 任务栏通知窗口
- Java实现QQ窗口自动输入