仿QQ 窗体拖到 windows窗体边上时,C#WinForm 自动隐藏

转载 2011年01月22日 09:48:00

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer();
            StopRectTimer.Tick += new EventHandler(timer1_Tick);
            StopRectTimer.Interval = 50;
            StopRectTimer.Enabled = true;
            this.TopMost = true;
            StopRectTimer.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Bounds.Contains(Cursor.Position))
            {
                switch (this.StopAanhor)
                {
                    case AnchorStyles.Top:
                        this.Location = new Point(this.Location.X, 0);
                        break;
                    case AnchorStyles.Left:
                        this.Location = new Point(0, this.Location.Y);
                        break;
                    case AnchorStyles.Right:
                        this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
                        break;
                    case AnchorStyles.Bottom:
                        this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height);
                        break;
                }
            }
            else
            {
                switch (this.StopAanhor)
                {
                    case AnchorStyles.Top:
                        this.Location = new Point(this.Location.X, (this.Height - 8) * (-1));
                        break;
                    case AnchorStyles.Left:
                        this.Location = new Point((-1) * (this.Width - 8), this.Location.Y);
                        break;
                    case AnchorStyles.Right:
                        this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 8, this.Location.Y);
                        break;
                    case AnchorStyles.Bottom:
                        this.Location = new Point(this.Location.X, (Screen.PrimaryScreen.Bounds.Height - 8));
                        break;
                }
            }

        }

        internal AnchorStyles StopAanhor = AnchorStyles.None;
        private void mStopAnhor()
        {
            if (this.Top <= 0 && this.Left <= 0)
            {
                StopAanhor = AnchorStyles.None;
            }
            else if (this.Top <= 0)
            {
                StopAanhor = AnchorStyles.Top;
            }
            else if (this.Left <= 0)
            {
                StopAanhor = AnchorStyles.Left;
            }
            else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width)
            {
                StopAanhor = AnchorStyles.Right;
            }
            else if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height)
            {
                StopAanhor = AnchorStyles.Bottom;
            }
            else
            {
                StopAanhor = AnchorStyles.None;
            }
        }

        private void hide_LocationChanged(object sender, EventArgs e)
        {
            this.mStopAnhor();
        }

}

在WinForm中添加Load事件给Form1_Load,添加LocationChanged事件给hide_LocationChanged。

原理:主要是用Timer控件,在实时判断当前窗口的位置,如果在windows窗口的边上时,

         修改窗口的位置。当窗口隐藏后,实时判断鼠标的位置,如果在窗口附件,窗口显示。

C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm

C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm。代码:     public partial class Form1 : Form { ...

仿QQ窗体自动隐藏.pas

  • 2012年09月11日 17:26
  • 5KB
  • 下载

Qt实现窗体在显示屏旁边自动隐藏(类似QQ)

Qt实现窗体在显示屏旁边自动隐藏(类似QQ)看群里有人问这个东西,本人先来无事编以自己的想法实现了下: 其实实现的点子很简单:void AutoHideWidget::leaveEvent(QEve...

winform自动隐藏窗体

  • 2013年01月06日 20:45
  • 6KB
  • 下载

Java实现窗体隐藏,功能类似于QQ窗口自动隐藏

自己写java程序从开始接触到现在有近两年的时间了,一直还没有怎么接触到j2ee方面的知识,比如说那些常用的框架(struts、spring、hibernate),自己都还没接触过。最近做项目又做到与...
  • ycb1689
  • ycb1689
  • 2012年04月16日 11:38
  • 894

C#-WinForm登录窗体实现记住密码的功能(仿QQ实现)

http://blog.csdn.net/gatieme/article/details/47360703

Swing中窗体移到屏幕边缘自动隐藏

开源中国看到的,跟大家分享一下,可以实现qq那样的屏幕边缘隐藏效果。 使用方法:new WindowAutoHide(window);  //window为java.awt.Window或其子类 ...

WPF 系统托盘制作方案与窗体自动隐藏

//系统托盘制作(引用命名空间System.Windows.Forms.NotifyIcon) using System; using System.ComponentModel; us...

Swing中窗体移到屏幕边缘自动隐藏

实现类似qq的屏幕边缘隐藏效果。 使用方法:new WindowAutoHide(window);  //window为java.awt.Window或其子类 根据实际需要,有以下参数可调: i...
  • ycb1689
  • ycb1689
  • 2014年01月03日 09:37
  • 1356
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:仿QQ 窗体拖到 windows窗体边上时,C#WinForm 自动隐藏
举报原因:
原因补充:

(最多只允许输入30个字)