improve:计时器UI
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
Topmost="True" Background="Transparent"
|
||||
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
|
||||
WindowStartupLocation="Manual" Title="计时器" Height="120" Width="300"
|
||||
MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseEnter="Window_MouseEnter" MouseLeave="Window_MouseLeave"
|
||||
ResizeMode="NoResize">
|
||||
WindowStartupLocation="Manual" Title="计时器" Height="120" Width="350"
|
||||
MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseLeftButtonUp="Window_MouseLeftButtonUp"
|
||||
MouseEnter="Window_MouseEnter" MouseLeave="Window_MouseLeave" MouseMove="Window_MouseMove">
|
||||
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
@@ -33,18 +33,18 @@
|
||||
<!-- 小时 -->
|
||||
<Path x:Name="MinHour1Display" Data="{StaticResource Digit0}"
|
||||
Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
|
||||
Width="24" Height="24"
|
||||
Width="32" Height="32"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,2,0"/>
|
||||
Margin="0,0,4,0"/>
|
||||
<Path x:Name="MinHour2Display" Data="{StaticResource Digit0}"
|
||||
Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
|
||||
Width="24" Height="24"
|
||||
Width="32" Height="32"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,2,0"/>
|
||||
Margin="0,0,4,0"/>
|
||||
|
||||
<!-- 冒号 -->
|
||||
<TextBlock Text=":" FontSize="20" FontWeight="Bold"
|
||||
@@ -55,18 +55,18 @@
|
||||
<!-- 分钟 -->
|
||||
<Path x:Name="MinMinute1Display" Data="{StaticResource Digit0}"
|
||||
Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
|
||||
Width="24" Height="24"
|
||||
Width="32" Height="32"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,2,0"/>
|
||||
Margin="0,0,4,0"/>
|
||||
<Path x:Name="MinMinute2Display" Data="{StaticResource Digit0}"
|
||||
Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
|
||||
Width="24" Height="24"
|
||||
Width="32" Height="32"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,2,0"/>
|
||||
Margin="0,0,4,0"/>
|
||||
|
||||
<!-- 冒号 -->
|
||||
<TextBlock Text=":" FontSize="20" FontWeight="Bold"
|
||||
@@ -77,14 +77,14 @@
|
||||
<!-- 秒 -->
|
||||
<Path x:Name="MinSecond1Display" Data="{StaticResource Digit0}"
|
||||
Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
|
||||
Width="24" Height="24"
|
||||
Width="32" Height="32"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,2,0"/>
|
||||
Margin="0,0,4,0"/>
|
||||
<Path x:Name="MinSecond2Display" Data="{StaticResource Digit0}"
|
||||
Fill="{DynamicResource SeewoTimerWindowDigitForeground}"
|
||||
Width="24" Height="24"
|
||||
Width="32" Height="32"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
|
||||
@@ -16,15 +16,17 @@ namespace Ink_Canvas
|
||||
private SeewoStyleTimerWindow parentWindow;
|
||||
private System.Timers.Timer updateTimer;
|
||||
private bool isMouseOver = false;
|
||||
private bool isDragging = false;
|
||||
private Point lastMousePosition;
|
||||
|
||||
public MinimizedTimerWindow(SeewoStyleTimerWindow parent)
|
||||
{
|
||||
InitializeComponent();
|
||||
parentWindow = parent;
|
||||
|
||||
// 设置窗口位置(在父窗口右下角)
|
||||
this.Left = parent.Left + parent.Width - this.Width - 20;
|
||||
this.Top = parent.Top + parent.Height - this.Height - 20;
|
||||
// 设置窗口位置(保持父窗口的位置)
|
||||
this.Left = parent.Left;
|
||||
this.Top = parent.Top;
|
||||
|
||||
// 启动更新定时器
|
||||
updateTimer = new System.Timers.Timer(100); // 100ms更新一次
|
||||
@@ -139,16 +141,52 @@ namespace Ink_Canvas
|
||||
|
||||
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// 恢复主窗口
|
||||
if (parentWindow != null)
|
||||
// 记录点击时间
|
||||
lastClickTime = DateTime.Now;
|
||||
// 开始拖动
|
||||
isDragging = true;
|
||||
lastMousePosition = e.GetPosition(this);
|
||||
this.CaptureMouse();
|
||||
}
|
||||
|
||||
private void Window_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (isDragging)
|
||||
{
|
||||
parentWindow.Show();
|
||||
parentWindow.Activate();
|
||||
parentWindow.WindowState = WindowState.Normal;
|
||||
this.Close();
|
||||
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)
|
||||
{
|
||||
parentWindow.Show();
|
||||
parentWindow.Activate();
|
||||
parentWindow.WindowState = WindowState.Normal;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime lastClickTime = DateTime.Now;
|
||||
|
||||
private void Window_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
isMouseOver = true;
|
||||
|
||||
Reference in New Issue
Block a user