From b84806338c7436c6d76b391d7402ed240b1c1140 Mon Sep 17 00:00:00 2001 From: crazypeace Date: Sun, 2 Jul 2023 20:34:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=9A=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=20=E8=8E=B7=E5=8F=96=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=BF=90=E8=A1=8C=E6=89=80=E5=9C=A8=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E7=9A=84DPI=E7=BC=A9=E6=94=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2rayN/Converters/MaterialDesignFonts.cs | 3 +- v2rayN/v2rayN/Handler/MainFormHandler.cs | 4 +- v2rayN/v2rayN/Tool/Utils.cs | 1 + .../v2rayN/ViewModels/AddServer2ViewModel.cs | 1 + .../v2rayN/ViewModels/MainWindowViewModel.cs | 2 + .../ViewModels/RoutingRuleSettingViewModel.cs | 1 + v2rayN/v2rayN/Views/AddServer2Window.xaml.cs | 39 +++++++++++------ v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 39 +++++++++++------ v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs | 39 +++++++++++------ .../Views/GlobalHotkeySettingWindow.xaml.cs | 39 +++++++++++------ v2rayN/v2rayN/Views/MainWindow.xaml.cs | 39 +++++++++++------ .../v2rayN/Views/OptionSettingWindow.xaml.cs | 42 +++++++++++++------ .../Views/RoutingRuleDetailsWindow.xaml.cs | 39 +++++++++++------ .../Views/RoutingRuleSettingWindow.xaml.cs | 39 +++++++++++------ .../v2rayN/Views/RoutingSettingWindow.xaml.cs | 39 +++++++++++------ v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 39 +++++++++++------ v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 39 +++++++++++------ 17 files changed, 309 insertions(+), 135 deletions(-) diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index bf58c4cd..e6169a25 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -1,4 +1,5 @@ -using v2rayN.Handler; +using System.Windows.Media; +using v2rayN.Handler; using FontFamily = System.Windows.Media.FontFamily; namespace v2rayN.Converters diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 556432d6..b879b7de 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -1,4 +1,6 @@ -using System.IO; +using Microsoft.Win32; +using System.Drawing; +using System.IO; using System.Windows.Media.Imaging; using v2rayN.Mode; using v2rayN.Resx; diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index c83f231d..b1bc7084 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NLog; using System.Diagnostics; +using System.Drawing; using System.IO; using System.IO.Compression; using System.Net; diff --git a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs index dcd5cc93..9255f228 100644 --- a/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServer2ViewModel.cs @@ -1,3 +1,4 @@ +using Microsoft.Win32; using ReactiveUI; using ReactiveUI.Fody.Helpers; using ReactiveUI.Validation.Helpers; diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 031e485f..13313dcb 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -3,10 +3,12 @@ using DynamicData.Binding; using MaterialDesignColors; using MaterialDesignColors.ColorManipulation; using MaterialDesignThemes.Wpf; +using Microsoft.Win32; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Splat; using System.Diagnostics; +using System.Drawing; using System.IO; using System.Reactive; using System.Reactive.Linq; diff --git a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs index 992f9aeb..07ee7d69 100644 --- a/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/RoutingRuleSettingViewModel.cs @@ -2,6 +2,7 @@ using ReactiveUI; using ReactiveUI.Fody.Helpers; using Splat; +using Microsoft.Win32; using System.Reactive; using System.Windows; using v2rayN.Base; diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs index c1d57e00..9cdfb80b 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs @@ -42,12 +42,6 @@ namespace v2rayN.Views { txtRemarks.Focus(); - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -56,20 +50,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index 72bce547..a39c00eb 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -174,12 +174,6 @@ namespace v2rayN.Views { txtRemarks.Focus(); - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -188,20 +182,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index 6937f37d..9e14305d 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -42,12 +42,6 @@ namespace v2rayN.Views private void Window_Loaded(object sender, RoutedEventArgs e) { - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -56,20 +50,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index f5eaa78c..8e9ced7a 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -37,12 +37,6 @@ namespace v2rayN.Views private void Window_Loaded(object sender, RoutedEventArgs e) { - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -51,20 +45,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index e1a9bbe6..9ea47a2a 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -238,12 +238,6 @@ namespace v2rayN.Views private void Window_Loaded(object sender, RoutedEventArgs e) { - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -252,20 +246,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 5ae3ee78..1a268da7 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -1,4 +1,5 @@ -using ReactiveUI; +using Microsoft.Win32; +using ReactiveUI; using System.Globalization; using System.IO; using System.Reactive.Disposables; @@ -185,12 +186,6 @@ namespace v2rayN.Views private void Window_Loaded(object sender, RoutedEventArgs e) { - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -199,20 +194,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 6a89f206..62337b01 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -61,12 +61,6 @@ namespace v2rayN.Views { cmbOutboundTag.Focus(); - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -75,20 +69,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index c8c40abf..b67a091f 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -66,12 +66,6 @@ namespace v2rayN.Views { txtRemarks.Focus(); - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -80,20 +74,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index 43f1b8f5..08bc298c 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -72,12 +72,6 @@ namespace v2rayN.Views private void Window_Loaded(object sender, RoutedEventArgs e) { - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -86,20 +80,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index 9423708a..96d026e9 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -42,12 +42,6 @@ namespace v2rayN.Views { txtRemarks.Focus(); - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -56,20 +50,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } } diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index 2be73fcb..7b89d518 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -36,12 +36,6 @@ namespace v2rayN.Views private void Window_Loaded(object sender, RoutedEventArgs e) { - // 获取当前屏幕的尺寸 - var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); - var screenWidth = screen.WorkingArea.Width; - var screenHeight = screen.WorkingArea.Height; - var screenTop = screen.WorkingArea.Top; - // 获取屏幕的 DPI 缩放因素 double dpiFactor = 1; PresentationSource source = PresentationSource.FromVisual(this); @@ -50,20 +44,41 @@ namespace v2rayN.Views dpiFactor = source.CompositionTarget.TransformToDevice.M11; } + // 获取当前屏幕的尺寸 + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); + var screenWidth = screen.WorkingArea.Width / dpiFactor; + var screenHeight = screen.WorkingArea.Height / dpiFactor; + var screenTop = screen.WorkingArea.Top / dpiFactor; + var screenLeft = screen.WorkingArea.Left / dpiFactor; + var screenBottom = screen.WorkingArea.Bottom / dpiFactor; + var screenRight = screen.WorkingArea.Right / dpiFactor; + // 设置窗口尺寸不超过当前屏幕的尺寸 - if (this.Width > screenWidth / dpiFactor) + if (this.Width > screenWidth) { - this.Width = screenWidth / dpiFactor; + this.Width = screenWidth; } - if (this.Height > screenHeight / dpiFactor) + if (this.Height > screenHeight) { - this.Height = screenHeight / dpiFactor; + this.Height = screenHeight; } // 设置窗口不要显示在屏幕外面 - if (this.Top < screenTop / dpiFactor) + if (this.Top < screenTop) { - this.Top = screenTop / dpiFactor; + this.Top = screenTop; + } + if (this.Left < screenLeft) + { + this.Left = screenLeft; + } + if (this.Top + this.Height > screenBottom) + { + this.Top = screenBottom - this.Height; + } + if (this.Left + this.Width > screenRight) + { + this.Left = screenRight - this.Width; } }