当窗体离屏幕四周一定距离时,改变窗体位置,引导窗体靠边;靠边后,当鼠标离开窗体时,改变窗体位置,窗体隐藏,凸出一点在屏幕内;隐藏后,当鼠标移到窗体时,窗体显示。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace FrmZoom
{
    public partial class FrmMain : Form
    {
        // 窗体是否引导
        bool isGuide = false;
        // 窗体是否隐藏
        bool isShrink = false;
        // 窗体引导距离
        const int GUIDE_DISTANCE = ;
        // 窗体靠边凸出部分距离
        const int BULGE_DISTANCE = ;         public FrmMain()
        {
            InitializeComponent();
        }         private void Form1_Load(object sender, EventArgs e)
        {
            // 设置500毫秒检查一次窗体是否需要缩放
            this.timZoom.Interval = ;
            // 启动窗体缩放事件
            this.timZoom.Enabled = true;
        }         /// <summary>
        /// 引导窗体
        /// </summary>
        private void GuideFrm()
        {
            /* 判断窗体边缘是否进入引导距离
             * true     靠边,“isGuide = false;”,窗体已引导
             * false    “isGuide = false;”,窗体未引导
             */
            if (this.Left < GUIDE_DISTANCE && this.Left > -GUIDE_DISTANCE)
            {
                this.Left = ;
                isGuide = true;
            }
            else if (this.Top < GUIDE_DISTANCE && this.Top > -GUIDE_DISTANCE)
            {
                this.Top = ;
                isGuide = true;
            }
            else if (this.Right < (Screen.GetWorkingArea(this).Width + GUIDE_DISTANCE) && this.Right > (Screen.GetWorkingArea(this).Width - GUIDE_DISTANCE))
            {
                this.Left = Screen.GetWorkingArea(this).Width - this.Width;
                isGuide = true;
            }
            else
            {
                isGuide = false;
            }
        }         /// <summary>
        /// 隐藏窗体
        /// </summary>
        private void HideFrm()
        {
            /* 窗体是否靠边
             * true     窗体隐藏
             * false    
             */
            if (this.Left == )
            {
                this.Left = -(this.Width - BULGE_DISTANCE);
            }
            else if (this.Top == )
            {
                this.Top = -(this.Height - BULGE_DISTANCE);
            }
            else if (this.Right == (Screen.GetWorkingArea(this).Width))
            {
                this.Left = Screen.GetWorkingArea(this).Width - BULGE_DISTANCE;
            }
            // 窗体已隐藏
            isShrink = true;
            // 窗体引导关闭
            isGuide = false;             // 窗体置顶
            this.TopMost = true;
            // 在Windows任务栏中不显示窗体
            this.ShowInTaskbar = false;
        }         /// <summary>
        /// 显示窗体
        /// </summary>
        private void ShowFrm()
        {
            // 窗体是否靠边
            if (this.Left == -(this.Width - BULGE_DISTANCE))
            {
                this.Left = ;
            }
            else if (this.Top == -(this.Height - BULGE_DISTANCE))
            {
                this.Top = ;
            }
            else if (this.Right == Screen.GetWorkingArea(this).Width + this.Width - BULGE_DISTANCE)
            {
                this.Left = Screen.GetWorkingArea(this).Width - this.Width;
            }
            // 窗体未隐藏
            isShrink = false;             // 窗口不置顶
            this.TopMost = false;
            // 在Windows任务栏中显示窗体
            this.ShowInTaskbar = true;
        }         /// <summary>
        /// 窗体缩放
        /// </summary>
        private void ZoomFrm()
        {
            // 获取鼠标位置
            int mouseX = MousePosition.X;
            int mouseY = MousePosition.Y;
            // 获取窗体位置
            int frmX = this.Location.X;
            int frmY = this.Location.Y;             /* 鼠标是否在窗体内
             * true     显示窗体
             * false    隐藏窗体
             */
            if (mouseX > frmX - && mouseX < frmX + this.Width + && mouseY > frmY - && mouseY < frmY + this.Height + )
            {
                // 窗体隐藏时才显示窗体
                if (isShrink)
                {
                    ShowFrm();
                }
            }
            else
            {
                // 窗体引导时才隐藏窗体
                if (isGuide)
                {
                    HideFrm();
                }
            }
        }         /// <summary>
        /// 移动窗体事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmMain_Move(object sender, EventArgs e)
        {
            // 引导窗体
            GuideFrm();
        }         /// <summary>
        /// 窗体缩放事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timZoom_Tick(object sender, EventArgs e)
        {
            // 缩放窗体
            ZoomFrm();
        }
    }
}

示例项目:http://download.csdn.net/detail/u011689438/8823845

C# WinForm 类似QQ靠近屏幕边缘隐藏显示的更多相关文章

  1. C# winform 实现 qq 在屏幕边缘 自动隐藏 鼠标移过去 移上去 又自动显示

    代码下载地址   http://download.csdn.net/detail/simadi/7677147

  2. winform-实现类似QQ停靠桌面上边缘隐藏的效果

    //实现类似QQ停靠桌面上边缘隐藏的效果! private void timer1_Tick(object sender, EventArgs e) { System.Drawing.Point pp ...

  3. C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)

    using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; us ...

  4. C# WPF 仿QQ靠近屏幕上方自动缩起功能实现

    碰到了类似需求,但是上网查了一圈发现感觉要么很复杂,要么代码很臃肿,索性自己实现了一个 几乎和QQ是一模一样的效果,而且核心代码只有20行左右. 代码如下: using System; using S ...

  5. JS实现类似QQ好友头像hover时显示资料卡的效果

    一.应用场景 鼠标hover弹出div,并且鼠标离开后不能马上隐藏,因为这个div上还有功能入口.比如: 鼠标经过好友列表中的好友头像时显示资料卡的效果 hover时显示二维码 二.实现 用如下这样一 ...

  6. C# 实现窗口程序winform像QQ一样靠近桌面边缘自动隐藏窗口

    实现原理: 实现这个功能的原理步骤如下: 1.判断窗体程序是否靠近桌面边缘: 2.获取桌面屏幕大小与窗体程序大小: 3.把窗体程序显示在桌面以外隐藏起来,预留部分窗体方便用户拉出程序: 4.判断鼠标是 ...

  7. C#:winform窗体 实现类似QQ的窗体在桌面边缘停靠和隐藏

    设计思路:1.使用定时器(Timer)来监控鼠标位置和窗体位置,并实现窗体的停靠和隐藏2.当鼠标拖动窗体时,窗体才有可能根据自身位置决定是否停靠3.如果窗体四周没有接触到屏幕边缘则不会停靠4.如果窗体 ...

  8. winform, 实现窗口程序像QQ一样靠近桌面边缘自动隐藏窗口

    实现原理: 步骤如下: 1.判断窗体程序是否靠近桌面边缘: 2.获取桌面屏幕大小与窗体程序大小: 3.把窗体程序显示在桌面以外隐藏起来,预留部分窗体方便用户拉出程序: 4.判断鼠标是否在窗体程序上,在 ...

  9. WinForm实现类似QQ停靠,显示隐藏过程添加特效效果

    原文:WinForm实现类似QQ停靠,显示隐藏过程添加特效效果 这可能是个老题长谈的问题了,只是在项目中会用到这个效果,所以今天做个记录.大家见了别喷我.在项目中的需求是这样的. 打开程序,在屏幕的右 ...

随机推荐

  1. Object instanceof Function和Function instanceof Object

    首先需要确定的是,instanceof是根据原型链来判断是否为某引用类型的实例.所以需要明白Object和Function之间的关系,以下为引用某博客的图片,阐述了javascript对象体系的关系 ...

  2. SpringMVC实现注解式权限验证

    SpringMVC学习系列(9) 之 实现注解式权限验证 对大部分系统来说都需要权限管理来决定不同用户可以看到哪些内容,那么如何在Spring MVC中实现权限验证呢?当然我们可以继续使用servle ...

  3. psql: FATAL: role “postgres” does not exist 解决方案

    当时想做的事情,是运行一个创建数据库的脚本.找到的解决方案差不多和下面这个链接相同. http://stackoverflow.com/questions/15301826/psql-fatal-ro ...

  4. SharpDevelop插件开发手册

    SharpDevelop插件开发手册部分内容摘取自:http://www.cnblogs.com/CBuilder的SharpDevelop开发教程 SharpDevelop插件开发手册 第一章    ...

  5. IOS UI 第一篇:基本UI

    1. UI 书写 最基本创建一个label 标签 写一个first rate :      UILabel *label = [[UILabel alloc] initWithFrame:CGRect ...

  6. 图片缩放+拖动(html)

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowImg.aspx.cs& ...

  7. Python 用SMTP发送邮件

    一.简介 上面介绍了传统邮件的生成和解析,这些都是non-internet,也就是不需要网络就可一完成的.那么当生成了邮件,下一步就是发送了,本文就讲解利用SMTP协议发送邮件. 正如SMTP(Sim ...

  8. [原]iOS Makefile Template

    export DEVELOPER_DIR := $(shell xcode-select --print-path) PLATFORM="$(DEVELOPER_DIR)/Platforms ...

  9. Linux环境进程间通信(二):信号(下)

    linux下进程间通信的几种主要手段: 管道(Pipe)及有名管道(named pipe):管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具有的功能外,它还允 ...

  10. CentOS安装Python教程

    下载/安装python yum install -y bzip2* #nodejs 0.8.5需要,请安装python前,先安装此模块.   wget http://www.python.org/ft ...