improve:计时器
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
Topmost="True" Background="Transparent"
|
Topmost="True" Background="Transparent"
|
||||||
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
|
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
|
||||||
Loaded="Window_Loaded" Closing="Window_Closing" WindowStartupLocation="CenterScreen"
|
Loaded="Window_Loaded" Closing="Window_Closing" WindowStartupLocation="CenterScreen"
|
||||||
Title="Ink Canvas 画板 - 计时器" Height="400" Width="600">
|
Title="Ink Canvas 画板 - 计时器" Height="450" Width="900">
|
||||||
|
|
||||||
<Border Background="{DynamicResource SeewoTimerWindowBackground}" CornerRadius="15" BorderThickness="1" BorderBrush="{DynamicResource SeewoTimerWindowBorderBrush}" Margin="10">
|
<Border Background="{DynamicResource SeewoTimerWindowBackground}" CornerRadius="15" BorderThickness="1" BorderBrush="{DynamicResource SeewoTimerWindowBorderBrush}" Margin="10">
|
||||||
<Grid>
|
<Grid>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<Grid>
|
<Grid>
|
||||||
<!-- 使用Viewbox自动缩放内容 -->
|
<!-- 使用Viewbox自动缩放内容 -->
|
||||||
<Viewbox x:Name="MainViewController" Margin="20,20,20,20">
|
<Viewbox x:Name="MainViewController" Margin="20,20,20,20">
|
||||||
<Grid Height="350" Width="600">
|
<Grid Height="400" Width="900">
|
||||||
<!-- 顶部标题栏 -->
|
<!-- 顶部标题栏 -->
|
||||||
<Grid Height="50" Background="{DynamicResource SeewoTimerWindowBackground}" x:Name="TitleBar" HorizontalAlignment="Stretch" VerticalAlignment="Top">
|
<Grid Height="50" Background="{DynamicResource SeewoTimerWindowBackground}" x:Name="TitleBar" HorizontalAlignment="Stretch" VerticalAlignment="Top">
|
||||||
<TextBlock Text="计时" FontSize="20" FontWeight="Bold"
|
<TextBlock Text="计时" FontSize="20" FontWeight="Bold"
|
||||||
@@ -31,17 +31,20 @@
|
|||||||
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
<!-- 6位数字显示区域 -->
|
<!-- 主要内容区域 - 分为左右两部分 -->
|
||||||
<Grid HorizontalAlignment="Center" VerticalAlignment="Center"
|
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||||
x:Name="MainDisplayGrid">
|
x:Name="MainContentGrid" Margin="0,-25,0,25">
|
||||||
<!-- 6位数字水平排列 -->
|
<!-- 左侧:6位数字显示区域 -->
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
|
<Grid HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||||
x:Name="DigitsPanel" Margin="0,-25,0,25">
|
x:Name="MainDisplayGrid" Width="500" Margin="50,0,0,0">
|
||||||
|
<!-- 6位数字水平排列 -->
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
|
||||||
|
x:Name="DigitsPanel">
|
||||||
<!-- 小时组(十位和个位) -->
|
<!-- 小时组(十位和个位) -->
|
||||||
<Grid Margin="0,0,30,0" HorizontalAlignment="Center" Width="120">
|
<Grid Margin="0,0,40,0" HorizontalAlignment="Center" Width="140">
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
<!-- 第1位数字(小时十位) -->
|
<!-- 第1位数字(小时十位) -->
|
||||||
<Grid Margin="0,0,15,0">
|
<Grid Margin="0,0,20,0">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
||||||
<!-- 上方+按钮 -->
|
<!-- 上方+按钮 -->
|
||||||
<Button x:Name="Digit1PlusBtn" Width="40" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
<Button x:Name="Digit1PlusBtn" Width="40" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
@@ -112,10 +115,10 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<!-- 分钟组(十位和个位) -->
|
<!-- 分钟组(十位和个位) -->
|
||||||
<Grid Margin="0,0,30,0" HorizontalAlignment="Center" Width="120">
|
<Grid Margin="0,0,40,0" HorizontalAlignment="Center" Width="140">
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
<!-- 第3位数字(分钟十位) -->
|
<!-- 第3位数字(分钟十位) -->
|
||||||
<Grid Margin="0,0,15,0">
|
<Grid Margin="0,0,20,0">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
||||||
<!-- 上方+按钮 -->
|
<!-- 上方+按钮 -->
|
||||||
<Button x:Name="Digit3PlusBtn" Width="40" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
<Button x:Name="Digit3PlusBtn" Width="40" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
@@ -186,10 +189,10 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<!-- 秒组(十位和个位) -->
|
<!-- 秒组(十位和个位) -->
|
||||||
<Grid Width="120">
|
<Grid Width="140">
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
<!-- 第5位数字(秒十位) -->
|
<!-- 第5位数字(秒十位) -->
|
||||||
<Grid Margin="0,0,15,0">
|
<Grid Margin="0,0,20,0">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
||||||
<!-- 上方+按钮 -->
|
<!-- 上方+按钮 -->
|
||||||
<Button x:Name="Digit5PlusBtn" Width="40" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
<Button x:Name="Digit5PlusBtn" Width="40" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
@@ -259,7 +262,102 @@
|
|||||||
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}" Margin="0,112,0,-12"/>
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}" Margin="0,112,0,-12"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- 右侧:快捷选项区域 -->
|
||||||
|
<Grid HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
|
x:Name="QuickOptionsGrid" Width="350" Margin="30,0,0,0">
|
||||||
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
||||||
|
<!-- 第一排:5min, 10min -->
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,15">
|
||||||
|
<Button x:Name="Quick5MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
|
BorderThickness="0" Click="Quick5Min_Click" Cursor="Hand" Margin="0,0,15,0">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="8">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
<TextBlock Text="5分钟" FontSize="16" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
|
</Button>
|
||||||
|
<Button x:Name="Quick10MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
|
BorderThickness="0" Click="Quick10Min_Click" Cursor="Hand">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="8">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
<TextBlock Text="10分钟" FontSize="16" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- 第二排:15min, 20min -->
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,15">
|
||||||
|
<Button x:Name="Quick15MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
|
BorderThickness="0" Click="Quick15Min_Click" Cursor="Hand" Margin="0,0,15,0">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="8">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
<TextBlock Text="15分钟" FontSize="16" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
|
</Button>
|
||||||
|
<Button x:Name="Quick20MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
|
BorderThickness="0" Click="Quick20Min_Click" Cursor="Hand">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="8">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
<TextBlock Text="20分钟" FontSize="16" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- 第三排:最近两次计时 -->
|
||||||
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
|
||||||
|
<TextBlock Text="最近计时" FontSize="14" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"
|
||||||
|
HorizontalAlignment="Center" Margin="0,0,0,10"/>
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
|
<Button x:Name="RecentTimer1Btn" Width="80" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
|
BorderThickness="0" Click="RecentTimer1_Click" Cursor="Hand" Margin="0,0,10,0">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="6">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
<TextBlock x:Name="RecentTimer1Text" Text="--:--" FontSize="14" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
|
</Button>
|
||||||
|
<Button x:Name="RecentTimer2Btn" Width="80" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
|
||||||
|
BorderThickness="0" Click="RecentTimer2_Click" Cursor="Hand">
|
||||||
|
<Button.Template>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<Border Background="{TemplateBinding Background}" CornerRadius="6">
|
||||||
|
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Border>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Button.Template>
|
||||||
|
<TextBlock x:Name="RecentTimer2Text" Text="--:--" FontSize="14" FontWeight="Bold"
|
||||||
|
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<!-- 底部控制按钮区域 -->
|
<!-- 底部控制按钮区域 -->
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ namespace Ink_Canvas
|
|||||||
isTimerRunning = false;
|
isTimerRunning = false;
|
||||||
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
||||||
PlayTimerSound();
|
PlayTimerSound();
|
||||||
|
|
||||||
|
// 保存最近计时记录
|
||||||
|
SaveRecentTimer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -86,10 +89,15 @@ namespace Ink_Canvas
|
|||||||
bool isPaused = false;
|
bool isPaused = false;
|
||||||
|
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
|
|
||||||
|
// 最近计时记录
|
||||||
|
private string recentTimer1 = "--:--";
|
||||||
|
private string recentTimer2 = "--:--";
|
||||||
|
|
||||||
private void InitializeUI()
|
private void InitializeUI()
|
||||||
{
|
{
|
||||||
UpdateDigitDisplays();
|
UpdateDigitDisplays();
|
||||||
|
UpdateRecentTimerDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyTheme()
|
private void ApplyTheme()
|
||||||
@@ -537,5 +545,102 @@ namespace Ink_Canvas
|
|||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
DragMove();
|
DragMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 快捷选项事件处理
|
||||||
|
private void Quick5Min_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (isTimerRunning) return;
|
||||||
|
SetQuickTime(0, 5, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Quick10Min_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (isTimerRunning) return;
|
||||||
|
SetQuickTime(0, 10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Quick15Min_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (isTimerRunning) return;
|
||||||
|
SetQuickTime(0, 15, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Quick20Min_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (isTimerRunning) return;
|
||||||
|
SetQuickTime(0, 20, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RecentTimer1_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (isTimerRunning || recentTimer1 == "--:--") return;
|
||||||
|
ApplyRecentTimer(recentTimer1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RecentTimer2_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (isTimerRunning || recentTimer2 == "--:--") return;
|
||||||
|
ApplyRecentTimer(recentTimer2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置快捷时间
|
||||||
|
private void SetQuickTime(int h, int m, int s)
|
||||||
|
{
|
||||||
|
hour = h;
|
||||||
|
minute = m;
|
||||||
|
second = s;
|
||||||
|
UpdateDigitDisplays();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 应用最近计时
|
||||||
|
private void ApplyRecentTimer(string timeString)
|
||||||
|
{
|
||||||
|
if (timeString == "--:--") return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var parts = timeString.Split(':');
|
||||||
|
if (parts.Length == 2)
|
||||||
|
{
|
||||||
|
int minutes = int.Parse(parts[0]);
|
||||||
|
int seconds = int.Parse(parts[1]);
|
||||||
|
SetQuickTime(0, minutes, seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 如果解析失败,忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存最近计时记录
|
||||||
|
private void SaveRecentTimer()
|
||||||
|
{
|
||||||
|
if (hour == 0 && minute == 0 && second == 0) return;
|
||||||
|
|
||||||
|
string currentTime = $"{minute:D2}:{second:D2}";
|
||||||
|
|
||||||
|
// 如果当前时间与最近记录不同,则更新
|
||||||
|
if (currentTime != recentTimer1)
|
||||||
|
{
|
||||||
|
recentTimer2 = recentTimer1;
|
||||||
|
recentTimer1 = currentTime;
|
||||||
|
UpdateRecentTimerDisplays();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新最近计时显示
|
||||||
|
private void UpdateRecentTimerDisplays()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RecentTimer1Text.Text = recentTimer1;
|
||||||
|
RecentTimer2Text.Text = recentTimer2;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 如果UI元素还未初始化,忽略错误
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user