zoukankan      html  css  js  c++  java
  • 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();
            }
        }
    }

  • 相关阅读:
    复杂系统架构设计<1>
    DevExpress Applications<3>
    DevExpress Skins<2>
    DevExpress MVVM<1>
    Unity容器<1>
    spring cloud微服务快速教程之(九) Spring Cloud Alibaba--sentinel-限流、熔断降级
    spring cloud微服务快速教程之(八) Spring Cloud Alibaba--nacos(二)、配置中心
    spring cloud微服务快速教程之(七) Spring Cloud Alibaba--nacos(一)、服务注册发现
    小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
    spring cloud微服务快速教程之(六) 应用监控 spring boot admin
  • 原文地址:https://www.cnblogs.com/zzh1236/p/1894418.html
Copyright © 2011-2022 走看看