C#浮动的窗口如何实现

        public class Win32API
        {
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern bool PtInRect(ref Rectangle r, Point p);
        }

        /// <summary>
        /// 停靠到顶端
        /// </summary>
        private void BerthTop(object sender, EventArgs e)
        {
            System.Drawing.Point pp = new Point(Cursor.Position.X, Cursor.Position.Y);
            Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);
            if ((this.Top < 0) && Win32API.PtInRect(ref Rects, pp))
            {
                this.Top = 0;
            }
            else if ((this.Top > -5) && (this.Top < 5) && !(Win32API.PtInRect(ref Rects, pp)))
            {
                this.Top = 5 - this.Height;
            }
        }

        private void setTouMing()
        {
            frmSetOpaticy opa = new frmSetOpaticy(this);
            opa.StartPosition = FormStartPosition.CenterScreen;
            opa.ShowDialog(this);
        }

 

 

 


        //private void timer1_Tick(object sender, EventArgs e)
        //{
        //    System.Drawing.Point pp = new Point(Cursor.Position.X, Cursor.Position.Y);//获取鼠标在屏幕的坐标点
        //    Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);//存储当前窗体在屏幕的所在区域
        //    if ((this.Top < 0) && Win32API.PtInRect(ref Rects, pp))//当鼠标在当前窗体内,并且窗体的Top属性小于0
        //        this.Top = 0;              //设置窗体的Top属性为0,就是将窗口上边沿紧靠顶部         
        //    else if (this.Top > -5 && this.Top < 5 && !(Win32API.PtInRect(ref Rects, pp)))//当窗体的上边框与屏幕的顶端的距离小于5时
        //        this.Top = 5 - this.Height;//将QQ窗体隐藏到屏幕的顶端
        //}

转载于:https://www.cnblogs.com/jason_yjau/archive/2010/10/28/1863143.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值