C#笔记(10)窗口靠边隐藏

来源:互联网 发布:earthview 数据 编辑:程序博客网 时间:2024/05/22 06:40

给窗口添加以下事件
MouseEnter//鼠标获得焦点
MouseLeave//鼠标失去焦点
MouseHover//鼠标停留
然后写代码:

        public Timer hoverTimer;        hoverTimer = new Timer();        hoverTimer.Interval = 3000;//定时周期3秒        hoverTimer.Tick += new EventHandler(hover);//到3秒了自动隐藏        hoverTimer.Enabled = true; //是否不断重复定时器操作        hoverTimer.Start();        void hover(object O, EventArgs ev)        {            if(this.Location.Y<5)                this.Location = new Point(this.Location.X, -64);        }        private void Form3_MouseEnter(object sender, EventArgs e)        {            if (this.Location.Y < -60)//已隐藏                this.Location = new System.Drawing.Point(this.Location.X, 0);        }        private void Form3_MouseHover(object sender, EventArgs e)        {            hoverTimer.Stop();//关闭计时器            hoverTimer.Start();//重新计时        }        private void Form3_MouseLeave(object sender, EventArgs e)        {            if (this.Location.Y < 5)//靠边的时候            {                Point point = this.PointToClient(Control.MousePosition);                if (!(point.X >= 0 && point.X <= 693 && point.Y >= 0 && point.Y <= 66))//鼠标在窗口内                    this.Location = new System.Drawing.Point(this.Location.X, -64);            }        }
原创粉丝点击