添加项目文件。

This commit is contained in:
2025-12-07 20:25:27 +08:00
parent 52ad3bd1e4
commit b866365968
31 changed files with 16642 additions and 0 deletions

114
DragToolTipWindow.cs Normal file
View File

@@ -0,0 +1,114 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace DrillTools
{
/// <summary>
/// 拖动提示窗口,显示刀具信息
/// </summary>
public class DragToolTipWindow : Window
{
private readonly TextBlock _textBlock;
public DragToolTipWindow()
{
// 设置窗口样式
WindowStyle = WindowStyle.None;
AllowsTransparency = true;
Background = System.Windows.Media.Brushes.Transparent;
ShowInTaskbar = false;
Topmost = true;
IsHitTestVisible = false; // 不拦截鼠标事件
SizeToContent = SizeToContent.WidthAndHeight; // 根据内容自动调整大小
MaxWidth = 200; // 限制最大宽度
MaxHeight = 50; // 限制最大高度
// 创建内容容器
var border = new Border
{
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(224, 255, 255, 255)),
BorderBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 120, 212)),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(3),
Padding = new Thickness(5, 2, 5, 2),
Effect = new System.Windows.Media.Effects.DropShadowEffect
{
Color = System.Windows.Media.Colors.Black,
Direction = 315,
ShadowDepth = 2,
BlurRadius = 5,
Opacity = 0.3
}
};
// 创建文本显示
_textBlock = new TextBlock
{
FontWeight = FontWeights.Bold,
FontSize = 10, // 减小字体大小
TextTrimming = TextTrimming.CharacterEllipsis // 文本过长时显示省略号
};
border.Child = _textBlock;
Content = border;
}
/// <summary>
/// 设置刀具信息
/// </summary>
/// <param name="tool">刀具项</param>
public void SetToolInfo(ToolItem tool)
{
_textBlock.Text = $"T{tool.ToolNumber:D2} - {tool.Diameter:F3}mm";
}
/// <summary>
/// 更新窗口位置
/// </summary>
/// <param name="position">鼠标位置</param>
public void UpdatePosition(System.Windows.Point position)
{
// 将提示窗口显示在鼠标右下方,稍微偏移以避免遮挡
// 确保窗口不会超出屏幕边界
double left = position.X + 15;
double top = position.Y - 35;
// 获取屏幕尺寸
var screenWidth = SystemParameters.PrimaryScreenWidth;
var screenHeight = SystemParameters.PrimaryScreenHeight;
// 先设置位置,然后获取实际尺寸
Left = left;
Top = top;
// 确保窗口不会超出右边界
if (left + ActualWidth > screenWidth)
{
left = position.X - ActualWidth - 15;
}
// 确保窗口不会超出左边界
if (left < 0)
{
left = 5;
}
// 确保窗口不会超出下边界
if (top + ActualHeight > screenHeight)
{
top = position.Y - ActualHeight - 5;
}
// 确保窗口不会超出上边界
if (top < 0)
{
top = position.Y + 15;
}
// 重新设置最终位置
Left = left;
Top = top;
}
}
}