• C#中winform窗口做成QQ窗口那样能收缩在电脑屏幕的上方


     1 private void Form1_Load(object sender, EventArgs e)
     2         {
     3             
     4             System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer();
     5             StopRectTimer.Tick += new EventHandler(timer1_Tick);
     6             StopRectTimer.Interval = 50;
     7             StopRectTimer.Enabled = true;
     8             this.TopMost = true;
     9             StopRectTimer.Start();
    10         }
    11 
    12         private void timer1_Tick(object sender, EventArgs e)
    13         {
    14             if (this.Bounds.Contains(Cursor.Position))
    15             {
    16                 switch (this.StopAanhor)
    17                 {
    18                     case AnchorStyles.Top:
    19                         this.Location = new Point(this.Location.X, 0);
    20                         break;
    21                     case AnchorStyles.Left:
    22                         this.Location = new Point(0, this.Location.Y);
    23                         break;
    24                     case AnchorStyles.Right:
    25                         this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
    26                         break;
    27                     case AnchorStyles.Bottom:
    28                         this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height);
    29                         break;
    30                 }
    31             }
    32             else
    33             {
    34                 switch (this.StopAanhor)
    35                 {
    36                     case AnchorStyles.Top:
    37                         this.Location = new Point(this.Location.X, (this.Height - 8) * (-1));
    38                         break;
    39                     case AnchorStyles.Left:
    40                         this.Location = new Point((-1) * (this.Width - 8), this.Location.Y);
    41                         break;
    42                     case AnchorStyles.Right:
    43                         this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 8, this.Location.Y);
    44                         break;
    45                     case AnchorStyles.Bottom:
    46                         this.Location = new Point(this.Location.X, (Screen.PrimaryScreen.Bounds.Height - 8));
    47                         break;
    48                 }
    49             }
    50 
    51         }
    52 
    53         internal AnchorStyles StopAanhor = AnchorStyles.None;
    54         private void mStopAnhor()
    55         {
    56             if (this.Top <= 0 && this.Left <= 0)
    57             {
    58                 StopAanhor = AnchorStyles.None;
    59             }
    60             else if (this.Top <= 0)
    61             {
    62                 StopAanhor = AnchorStyles.Top;
    63             }
    64             else if (this.Left <= 0)
    65             {
    66                 StopAanhor = AnchorStyles.Left;
    67             }
    68             else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width)
    69             {
    70                 StopAanhor = AnchorStyles.Right;
    71             }
    72             else if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height)
    73             {
    74                 StopAanhor = AnchorStyles.Bottom;
    75             }
    76             else
    77             {
    78                 StopAanhor = AnchorStyles.None;
    79             }
    80         }
    81 
    82         private void hide_LocationChanged(object sender, EventArgs e)
    83         {
    84             this.mStopAnhor();
    85         }
    86 
    87 }

     【转载】

  • 相关阅读:
    已混淆和未混淆对Apk反编译后的影响
    Android WebView内有https图片链接显示失败解决方法
    微信小程序列表item绑定监听方法
    Mysql 解决1251 client does not support ...问题
    使用Python转换PDF,Word/Excel/PPT/md/HTML都能转!
    Django annotate 时 group by 有额外的字段
    odoo12 通过route返回一个自定义的html界面
    Django 运行odoo环境所生成数据库(Django运行ODOO环境)完美运行
    Flask 下载时数据流的返回
    Python
  • 原文地址:https://www.cnblogs.com/masonchi/p/3446034.html
Copyright © 2020-2023  润新知