From d9270ff3378868c380d28f45c3031ae9d667b73c Mon Sep 17 00:00:00 2001 From: liufei Date: Thu, 7 Apr 2022 20:28:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=BC=80=E5=90=AF=E8=B4=B4=E8=BE=B9?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E4=B8=8D=E5=86=8D=E5=8D=A0=E7=94=A8=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Util/MarginHide.cs | 48 +++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/Util/MarginHide.cs b/Util/MarginHide.cs index 88137ea..c539a0a 100644 --- a/Util/MarginHide.cs +++ b/Util/MarginHide.cs @@ -1,15 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Drawing; using System.Windows.Forms; -using MouseEventArgs = System.Windows.Input.MouseEventArgs; using System.Windows; using System.Windows.Media.Animation; -using System.Windows.Media; +using GeekDesk.Constant; namespace GeekDesk.Util { @@ -24,6 +18,7 @@ namespace GeekDesk.Util RIGHT_HIDE = 6 } + public class MarginHide { private static Window window;//定义使用该方法的窗体 @@ -33,9 +28,11 @@ namespace GeekDesk.Util private static readonly int fadeShowTime = 200; private static readonly int taskTime = 250; + public static readonly int shadowWidth = 20; + + private static double showMarginWidth = 1; - public static bool IS_RUN = false; public static bool IS_HIDE = false; private static Timer timer = null; @@ -43,11 +40,6 @@ namespace GeekDesk.Util public static void ReadyHide(Window window) { MarginHide.window = window; - if (timer != null) return; - timer = new Timer();//添加timer计时器,隐藏功能 - timer.Interval = taskTime; - timer.Tick += HideWindow; - timer.Start(); } @@ -77,7 +69,7 @@ namespace GeekDesk.Util #region 窗体贴边隐藏功能 private static void HideWindow(object o, EventArgs e) { - if (window.Visibility != Visibility.Visible || !IS_RUN) return; + if (window.Visibility != Visibility.Visible) return; double screenLeft = SystemParameters.VirtualScreenLeft; double screenTop = SystemParameters.VirtualScreenTop; @@ -158,12 +150,21 @@ namespace GeekDesk.Util public static void StartHide() { - IS_RUN = true; + if (timer != null) return; + timer = new Timer + { + Interval = taskTime + };//添加timer计时器,隐藏功能 + timer.Tick += HideWindow; + timer.Start(); } public static void StopHide() { - IS_RUN = false; + if (timer == null) return; + timer.Stop(); + timer.Dispose(); + timer = null; //功能关闭 如果界面是隐藏状态 那么要显示界面 ↓ if (IS_HIDE) { @@ -239,15 +240,26 @@ namespace GeekDesk.Util To = to, Duration = new Duration(TimeSpan.FromMilliseconds(hideTime)) }; + // 如果是显示 则贴屏幕侧不显示阴影 + bool isShow = false; + int shadowWidthTemp = Constants.SHADOW_WIDTH; + if (hideType <= HideType.RIGHT_SHOW) + { + isShow = true; + if (hideType == HideType.RIGHT_SHOW) + { + shadowWidthTemp = -shadowWidthTemp; + } + } da.Completed += (s, e) => { if ("Top".Equals(property.Name)) { - window.Top = toTemp; + window.Top = isShow ? toTemp - shadowWidthTemp : toTemp; } else { - window.Left = toTemp; + window.Left = isShow ? toTemp - shadowWidthTemp : toTemp; } window.BeginAnimation(property, null); };