zoukankan      html  css  js  c++  java
  • 转 实现类似QQ的窗体停靠

    [DllImport("User32.dll")]
            public static extern bool PtInRect(ref Rectangle Rects, Point lpPoint);
    
            private void timerShowHide_Tick(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Normal)
                {
                    System.Drawing.Point cursorPoint = new Point(Cursor.Position.X, Cursor.Position.Y);//获取鼠标在屏幕的坐标点
                    Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);//存储当前窗体在屏幕的所在区域
                    bool prInRect = PtInRect(ref Rects, cursorPoint);
                    if (prInRect)
                    {//当鼠标在当前窗体内
                        if (this.Top < 0)//窗体的Top属性小于0
                            this.Top = 0;
                        else if (this.Left < 0)//窗体的Left属性小于0
                            this.Left = 0;
                        else if (this.Right > Screen.PrimaryScreen.WorkingArea.Width)//窗体的Right属性大于屏幕宽度
                            this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
                    }
                    else
                    {
                        if (this.Top < 5)               //当窗体的上边框与屏幕的顶端的距离小于5时
                            this.Top = 5 - this.Height; //将窗体隐藏到屏幕的顶端
                        else if (this.Left < 5)         //当窗体的左边框与屏幕的左端的距离小于5时
                            this.Left = 5 - this.Width; //将窗体隐藏到屏幕的左端
                        else if (this.Right > Screen.PrimaryScreen.WorkingArea.Width - 5)//当窗体的右边框与屏幕的右端的距离小于5时
                            this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;//将窗体隐藏到屏幕的右端
                    }
                }
            }
    

      

  • 相关阅读:
    网络诊断工具:[tcpdump]
    网络诊断工具:iproute
    C语言编译全过程
    (Ruby)Ubuntu12.04安装Rails环境
    (Life)牛人的学习方法(转译文)
    (WPF)WPF事件要点WPF宝典笔记
    (WPF)依赖属性要点WPF宝典笔记
    (DP)降低代码重构的风险(转载)
    (WPF)路由事件要点WPF宝典笔记
    JDBC,MYBATIS,Hibernate性能对比!
  • 原文地址:https://www.cnblogs.com/xiangxiong/p/6549476.html
Copyright © 2011-2022 走看看