zoukankan      html  css  js  c++  java
  • C#中让窗体自动靠边隐藏

    private void Yincangtimer_Tick(object sender, EventArgs e)//窗体隐藏事件
            {
                int a = Control.MousePosition.Y;//光标的在屏幕中的 Y 坐标
                int b = Control.MousePosition.X;//光标的在屏幕中的 X 坐标
                int height = Screen.PrimaryScreen.WorkingArea.Height;//屏幕的高
                int width = Screen.PrimaryScreen.WorkingArea.Width;//屏幕的宽
                int x = this.Left;//窗体的在屏幕中的X坐标
                int y = this.Top;//窗体的在屏幕中的Y坐标
                //判断光标是否在窗体内
                if (b >= x && b <= (this.Width + x) && a >= y && a <= (this.Top + this.Height))
                {
                    return;
                }
                else
                {//隐藏窗体
                    if ((x + this.Width) >= width)
                    {
                        this.Top = this.Top;
                        this.Left = width - 5;
                    }
                    else if (x <= 0)
                    {
                        this.Top = this.Top;
                        this.Left = 5 - this.Width;
                    }
                    else if (y <= 0)
                    {
                        this.Left = this.Left;
                        this.Top = 5 - this.Height;

                    }
                    else
                    {

                        return;
                    }
                }
            }

    //光标离开窗体
            private void MainForm_MouseLeave(object sender, EventArgs e)
            {
                Yincangtimer.Start();
            }
            //光标进入窗体
            private void MainForm_MouseEnter(object sender, EventArgs e)
            {
                int height = Screen.PrimaryScreen.WorkingArea.Height;//屏幕的高
                int width = Screen.PrimaryScreen.WorkingArea.Width;//屏幕的宽
           
                if (this.Left < 0)
                {
                    this.Left = 0;
                    this.Top = this.Top;
                    Yincangtimer.Stop();
                }
                else if (this.Left > width - this.Width)
                {
                    this.Left = width - this.Width;
                    this.Top = this.Top;
                    Yincangtimer.Stop();
                }
                else if (this.Top <= 0)
                {
                    this.Left = this.Left;
                    this.Top = 0;
                    Yincangtimer.Stop();
                }

                else
                { return; }
            }

  • 相关阅读:
    Python学习笔记10:上下文协议
    Python学习笔记9:类
    使用率激增250%,这份报告再将 Serverless 推向幕前
    国内首篇云厂商 Serverless 论文入选全球顶会:突发流量下,如何加速容器启动?
    如何评估 Serverless 服务能力?这份报告给出了 40 条标准
    飞猪基于 Serverless 的云+端实践与思考
    Serverless:这真的是未来吗?(二)
    Serverless:这真的是未来吗?(一)
    被解救的代码
    云厂商下一块必争之地就是它了!
  • 原文地址:https://www.cnblogs.com/lqsilly/p/2917633.html
Copyright © 2011-2022 走看看