mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 14:26:20 +00:00
解决多屏幕环境下 获取程序运行所在屏幕的DPI缩放的问题
This commit is contained in:
parent
f1693bce64
commit
b84806338c
17 changed files with 309 additions and 135 deletions
|
@ -1,4 +1,5 @@
|
|||
using v2rayN.Handler;
|
||||
using System.Windows.Media;
|
||||
using v2rayN.Handler;
|
||||
using FontFamily = System.Windows.Media.FontFamily;
|
||||
|
||||
namespace v2rayN.Converters
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using Microsoft.Win32;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using ReactiveUI.Validation.Helpers;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Splat;
|
||||
using Microsoft.Win32;
|
||||
using System.Reactive;
|
||||
using System.Windows;
|
||||
using v2rayN.Base;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue