优化交互显示界面
This commit is contained in:
@@ -10,7 +10,7 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using static GeekDesk.Util.ShowWindowFollowMouse;
|
||||||
|
|
||||||
namespace GeekDesk.Control.Windows
|
namespace GeekDesk.Control.Windows
|
||||||
{
|
{
|
||||||
@@ -132,6 +132,7 @@ namespace GeekDesk.Control.Windows
|
|||||||
window = new IconfontWindow(listInfo, menuInfo);
|
window = new IconfontWindow(listInfo, menuInfo);
|
||||||
}
|
}
|
||||||
window.Show();
|
window.Show();
|
||||||
|
ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CustomButton_Click(object sender, RoutedEventArgs e)
|
private void CustomButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -173,6 +173,7 @@
|
|||||||
<Compile Include="Util\MouseUtilities.cs" />
|
<Compile Include="Util\MouseUtilities.cs" />
|
||||||
<Compile Include="Util\RegisterUtil.cs" />
|
<Compile Include="Util\RegisterUtil.cs" />
|
||||||
<Compile Include="Util\ShellContextMenu.cs" />
|
<Compile Include="Util\ShellContextMenu.cs" />
|
||||||
|
<Compile Include="Util\ShowWindowFollowMouse.cs" />
|
||||||
<Compile Include="Util\StringUtil.cs" />
|
<Compile Include="Util\StringUtil.cs" />
|
||||||
<Compile Include="Util\SvgToGeometry.cs" />
|
<Compile Include="Util\SvgToGeometry.cs" />
|
||||||
<Compile Include="ViewModel\AppConfig.cs" />
|
<Compile Include="ViewModel\AppConfig.cs" />
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using static GeekDesk.Util.ShowWindowFollowMouse;
|
||||||
|
|
||||||
namespace GeekDesk
|
namespace GeekDesk
|
||||||
{
|
{
|
||||||
@@ -260,7 +261,7 @@ namespace GeekDesk
|
|||||||
{
|
{
|
||||||
if (appData.AppConfig.FollowMouse)
|
if (appData.AppConfig.FollowMouse)
|
||||||
{
|
{
|
||||||
ShowAppAndFollowMouse();
|
ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
mainWindow.Visibility = Visibility.Visible;
|
mainWindow.Visibility = Visibility.Visible;
|
||||||
@@ -268,55 +269,8 @@ namespace GeekDesk
|
|||||||
Keyboard.Focus(mainWindow);
|
Keyboard.Focus(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 随鼠标位置显示面板 (鼠标始终在中间)
|
|
||||||
/// </summary>
|
|
||||||
private static void ShowAppAndFollowMouse()
|
|
||||||
{
|
|
||||||
//获取鼠标位置
|
|
||||||
System.Windows.Point p = MouseUtil.GetMousePosition();
|
|
||||||
double left = SystemParameters.VirtualScreenLeft;
|
|
||||||
double top = SystemParameters.VirtualScreenTop;
|
|
||||||
double width = SystemParameters.VirtualScreenWidth;
|
|
||||||
double height = SystemParameters.VirtualScreenHeight;
|
|
||||||
double right = width - Math.Abs(left);
|
|
||||||
double bottom = height - Math.Abs(top);
|
|
||||||
|
|
||||||
|
|
||||||
if (p.X - mainWindow.Width / 2 < left)
|
|
||||||
{
|
|
||||||
//判断是否在最左边缘
|
|
||||||
mainWindow.Left = left;
|
|
||||||
}
|
|
||||||
else if (p.X + mainWindow.Width / 2 > right)
|
|
||||||
{
|
|
||||||
//判断是否在最右边缘
|
|
||||||
mainWindow.Left = right - mainWindow.Width;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mainWindow.Left = p.X - mainWindow.Width / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (p.Y - mainWindow.Height / 2 < top)
|
|
||||||
{
|
|
||||||
//判断是否在最上边缘
|
|
||||||
mainWindow.Top = top;
|
|
||||||
}
|
|
||||||
else if (p.Y + mainWindow.Height / 2 > bottom)
|
|
||||||
{
|
|
||||||
//判断是否在最下边缘
|
|
||||||
mainWindow.Top = bottom - mainWindow.Height;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mainWindow.Top = p.Y - mainWindow.Height / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
mainWindow.Visibility = Visibility.Visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 图片图标单击事件
|
/// 图片图标单击事件
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using GeekDesk.Constant;
|
using GeekDesk.Constant;
|
||||||
using GeekDesk.ViewModel;
|
using GeekDesk.ViewModel;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 提取一些代码
|
/// 提取一些代码
|
||||||
@@ -53,6 +55,5 @@ namespace GeekDesk.Util
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
107
Util/ShowWindowFollowMouse.cs
Normal file
107
Util/ShowWindowFollowMouse.cs
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace GeekDesk.Util
|
||||||
|
{
|
||||||
|
public class ShowWindowFollowMouse
|
||||||
|
{
|
||||||
|
|
||||||
|
public enum MousePosition
|
||||||
|
{
|
||||||
|
CENTER = 1,
|
||||||
|
LEFT_TOP = 2,
|
||||||
|
LEFT_BOTTOM = 3,
|
||||||
|
RIGHT_TOP = 4,
|
||||||
|
RIGHT_BOTTOM = 5,
|
||||||
|
LEFT_CENTER = 6,
|
||||||
|
RIGHT_CENTER = 7
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 随鼠标位置显示面板 (鼠标始终在中间)
|
||||||
|
/// </summary>
|
||||||
|
public static void Show(Window window, MousePosition position, double widthOffset, double heightOffset)
|
||||||
|
{
|
||||||
|
//获取鼠标位置
|
||||||
|
System.Windows.Point p = MouseUtil.GetMousePosition();
|
||||||
|
double left = SystemParameters.VirtualScreenLeft;
|
||||||
|
double top = SystemParameters.VirtualScreenTop;
|
||||||
|
double width = SystemParameters.VirtualScreenWidth;
|
||||||
|
double height = SystemParameters.VirtualScreenHeight;
|
||||||
|
double right = width - Math.Abs(left);
|
||||||
|
double bottom = height - Math.Abs(top);
|
||||||
|
|
||||||
|
double afterWidth;
|
||||||
|
double afterHeight;
|
||||||
|
|
||||||
|
switch (position)
|
||||||
|
{
|
||||||
|
|
||||||
|
case MousePosition.LEFT_BOTTOM:
|
||||||
|
afterWidth = 0;
|
||||||
|
afterHeight = window.Height;
|
||||||
|
break;
|
||||||
|
case MousePosition.LEFT_TOP:
|
||||||
|
afterWidth = 0;
|
||||||
|
afterHeight = 0;
|
||||||
|
break;
|
||||||
|
case MousePosition.LEFT_CENTER:
|
||||||
|
afterWidth = 0;
|
||||||
|
afterHeight = window.Height / 2;
|
||||||
|
break;
|
||||||
|
case MousePosition.RIGHT_BOTTOM:
|
||||||
|
afterWidth = window.Width;
|
||||||
|
afterHeight = window.Height;
|
||||||
|
break;
|
||||||
|
case MousePosition.RIGHT_TOP:
|
||||||
|
afterWidth = window.Width;
|
||||||
|
afterHeight = 0;
|
||||||
|
break;
|
||||||
|
case MousePosition.RIGHT_CENTER:
|
||||||
|
afterWidth = window.Width;
|
||||||
|
afterHeight = window.Height / 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
afterWidth = window.Width / 2;
|
||||||
|
afterHeight = window.Height / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterWidth += widthOffset;
|
||||||
|
afterHeight -= heightOffset;
|
||||||
|
|
||||||
|
if (p.X - afterWidth < left)
|
||||||
|
{
|
||||||
|
//判断是否在最左边缘
|
||||||
|
window.Left = left;
|
||||||
|
}
|
||||||
|
else if (p.X + afterWidth > right)
|
||||||
|
{
|
||||||
|
//判断是否在最右边缘
|
||||||
|
window.Left = right - window.Width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.Left = p.X - afterWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (p.Y - afterHeight < top)
|
||||||
|
{
|
||||||
|
//判断是否在最上边缘
|
||||||
|
window.Top = top;
|
||||||
|
}
|
||||||
|
else if (p.Y + afterHeight > bottom)
|
||||||
|
{
|
||||||
|
//判断是否在最下边缘
|
||||||
|
window.Top = bottom - window.Height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.Top = p.Y - afterHeight;
|
||||||
|
}
|
||||||
|
window.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user