improve:计时器UI

This commit is contained in:
2025-10-06 19:46:14 +08:00
parent 3ef047fb41
commit f2b8d4014e
2 changed files with 61 additions and 23 deletions
+14 -14
View File
@@ -7,9 +7,9 @@
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
Topmost="True" Background="Transparent" Topmost="True" Background="Transparent"
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True" mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
WindowStartupLocation="Manual" Title="计时器" Height="120" Width="300" WindowStartupLocation="Manual" Title="计时器" Height="120" Width="350"
MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseEnter="Window_MouseEnter" MouseLeave="Window_MouseLeave" MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseLeftButtonUp="Window_MouseLeftButtonUp"
ResizeMode="NoResize"> MouseEnter="Window_MouseEnter" MouseLeave="Window_MouseLeave" MouseMove="Window_MouseMove">
<Window.Resources> <Window.Resources>
<ResourceDictionary> <ResourceDictionary>
@@ -33,18 +33,18 @@
<!-- 小时 --> <!-- 小时 -->
<Path x:Name="MinHour1Display" Data="{StaticResource Digit0}" <Path x:Name="MinHour1Display" Data="{StaticResource Digit0}"
Fill="{DynamicResource SeewoTimerWindowDigitForeground}" Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
Width="24" Height="24" Width="32" Height="32"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="Uniform" Stretch="Uniform"
Margin="0,0,2,0"/> Margin="0,0,4,0"/>
<Path x:Name="MinHour2Display" Data="{StaticResource Digit0}" <Path x:Name="MinHour2Display" Data="{StaticResource Digit0}"
Fill="{DynamicResource SeewoTimerWindowDigitForeground}" Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
Width="24" Height="24" Width="32" Height="32"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="Uniform" Stretch="Uniform"
Margin="0,0,2,0"/> Margin="0,0,4,0"/>
<!-- 冒号 --> <!-- 冒号 -->
<TextBlock Text=":" FontSize="20" FontWeight="Bold" <TextBlock Text=":" FontSize="20" FontWeight="Bold"
@@ -55,18 +55,18 @@
<!-- 分钟 --> <!-- 分钟 -->
<Path x:Name="MinMinute1Display" Data="{StaticResource Digit0}" <Path x:Name="MinMinute1Display" Data="{StaticResource Digit0}"
Fill="{DynamicResource SeewoTimerWindowDigitForeground}" Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
Width="24" Height="24" Width="32" Height="32"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="Uniform" Stretch="Uniform"
Margin="0,0,2,0"/> Margin="0,0,4,0"/>
<Path x:Name="MinMinute2Display" Data="{StaticResource Digit0}" <Path x:Name="MinMinute2Display" Data="{StaticResource Digit0}"
Fill="{DynamicResource SeewoTimerWindowDigitForeground}" Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
Width="24" Height="24" Width="32" Height="32"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="Uniform" Stretch="Uniform"
Margin="0,0,2,0"/> Margin="0,0,4,0"/>
<!-- 冒号 --> <!-- 冒号 -->
<TextBlock Text=":" FontSize="20" FontWeight="Bold" <TextBlock Text=":" FontSize="20" FontWeight="Bold"
@@ -77,14 +77,14 @@
<!-- 秒 --> <!-- 秒 -->
<Path x:Name="MinSecond1Display" Data="{StaticResource Digit0}" <Path x:Name="MinSecond1Display" Data="{StaticResource Digit0}"
Fill="{DynamicResource SeewoTimerWindowDigitForeground}" Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
Width="24" Height="24" Width="32" Height="32"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="Uniform" Stretch="Uniform"
Margin="0,0,2,0"/> Margin="0,0,4,0"/>
<Path x:Name="MinSecond2Display" Data="{StaticResource Digit0}" <Path x:Name="MinSecond2Display" Data="{StaticResource Digit0}"
Fill="{DynamicResource SeewoTimerWindowDigitForeground}" Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
Width="24" Height="24" Width="32" Height="32"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="Uniform" Stretch="Uniform"
@@ -16,15 +16,17 @@ namespace Ink_Canvas
private SeewoStyleTimerWindow parentWindow; private SeewoStyleTimerWindow parentWindow;
private System.Timers.Timer updateTimer; private System.Timers.Timer updateTimer;
private bool isMouseOver = false; private bool isMouseOver = false;
private bool isDragging = false;
private Point lastMousePosition;
public MinimizedTimerWindow(SeewoStyleTimerWindow parent) public MinimizedTimerWindow(SeewoStyleTimerWindow parent)
{ {
InitializeComponent(); InitializeComponent();
parentWindow = parent; parentWindow = parent;
// 设置窗口位置(父窗口右下角 // 设置窗口位置(保持父窗口的位置
this.Left = parent.Left + parent.Width - this.Width - 20; this.Left = parent.Left;
this.Top = parent.Top + parent.Height - this.Height - 20; this.Top = parent.Top;
// 启动更新定时器 // 启动更新定时器
updateTimer = new System.Timers.Timer(100); // 100ms更新一次 updateTimer = new System.Timers.Timer(100); // 100ms更新一次
@@ -138,6 +140,38 @@ namespace Ink_Canvas
} }
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 记录点击时间
lastClickTime = DateTime.Now;
// 开始拖动
isDragging = true;
lastMousePosition = e.GetPosition(this);
this.CaptureMouse();
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
var currentPosition = e.GetPosition(this);
var deltaX = currentPosition.X - lastMousePosition.X;
var deltaY = currentPosition.Y - lastMousePosition.Y;
this.Left += deltaX;
this.Top += deltaY;
}
}
private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (isDragging)
{
isDragging = false;
this.ReleaseMouseCapture();
// 如果点击时间很短,认为是单击,恢复主窗口
var clickDuration = DateTime.Now - lastClickTime;
if (clickDuration.TotalMilliseconds < 200) // 200ms内认为是单击
{ {
// 恢复主窗口 // 恢复主窗口
if (parentWindow != null) if (parentWindow != null)
@@ -148,6 +182,10 @@ namespace Ink_Canvas
this.Close(); this.Close();
} }
} }
}
}
private DateTime lastClickTime = DateTime.Now;
private void Window_MouseEnter(object sender, MouseEventArgs e) private void Window_MouseEnter(object sender, MouseEventArgs e)
{ {