• C#窗体靠边隐藏代码


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            /// <summary>
            /// 加载
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Form1_Load(object sender, EventArgs e)
            {
                Timer StopRectTimer = new Timer();
                StopRectTimer.Tick += new EventHandler(timer1_Tick);
                StopRectTimer.Interval = 100;//时间
                StopRectTimer.Enabled = true;
            }

            internal AnchorStyles StopAanhor = AnchorStyles.None;
            /// <summary>
            /// 窗体根据每秒一刷新。来隐藏窗体
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            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;
                    }
                }
                else
                {
                    switch (this.StopAanhor)
                    {
                        case AnchorStyles.Top:
                            this.Location = new Point(this.Location.X, (this.Height - 2) * (-1));
                            break;
                        case AnchorStyles.Left:
                            this.Location = new Point((-1) * (this.Width - 2), this.Location.Y);
                            break;
                        case AnchorStyles.Right:
                            this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
                            break;
                    }
                }
            }
            /// <summary>
            /// 来判断位置的隐藏
            /// </summary>
            private void mStopAnthor()
            {
                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
                {
                    StopAanhor = AnchorStyles.None;
                }
            }

            private void Form1_LocationChanged(object sender, EventArgs e)
            {
                this.mStopAnthor();
            }
        }
    }

  • 相关阅读:
    GitLab--简单使用
    Git
    GitLab--安装部署
    RabbitMQ--工作模式
    服务器上TIME_WAIT过多怎么处理
    LVS Nginx HAProxy区别
    部署 Kubernetes 集群(kubeadm方式)
    office选项-》高级-》显示 中, 显示此数目的“最近使用的文档” 为灰色,无法更改
    期末测验: 课程水平综合测验 (第10周)-程序题
    测验9: Python计算生态纵览 (第9周)-程序题
  • 原文地址:https://www.cnblogs.com/zzh1236/p/1894418.html
Copyright © 2020-2023  润新知