improve:计时器
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<Window x:Class="Ink_Canvas.FullscreenTimerWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Ink_Canvas"
|
||||
Topmost="True" Background="Black"
|
||||
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="False"
|
||||
WindowState="Maximized" WindowStartupLocation="Manual"
|
||||
MouseLeftButtonDown="Window_MouseLeftButtonDown"
|
||||
KeyDown="Window_KeyDown">
|
||||
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="DigitResources.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Background="Black">
|
||||
<!-- 时间显示 -->
|
||||
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<!-- 小时 -->
|
||||
<Path x:Name="FullHour1Display" Data="{StaticResource Digit0}"
|
||||
Fill="White"
|
||||
Width="120" Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,20,0"/>
|
||||
<Path x:Name="FullHour2Display" Data="{StaticResource Digit0}"
|
||||
Fill="White"
|
||||
Width="120" Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,20,0"/>
|
||||
|
||||
<!-- 冒号 -->
|
||||
<TextBlock Text=":" FontSize="120" FontWeight="Bold"
|
||||
Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Margin="0,0,20,0"/>
|
||||
|
||||
<!-- 分钟 -->
|
||||
<Path x:Name="FullMinute1Display" Data="{StaticResource Digit0}"
|
||||
Fill="White"
|
||||
Width="120" Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,20,0"/>
|
||||
<Path x:Name="FullMinute2Display" Data="{StaticResource Digit0}"
|
||||
Fill="White"
|
||||
Width="120" Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,20,0"/>
|
||||
|
||||
<!-- 冒号 -->
|
||||
<TextBlock Text=":" FontSize="120" FontWeight="Bold"
|
||||
Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Margin="0,0,20,0"/>
|
||||
|
||||
<!-- 秒 -->
|
||||
<Path x:Name="FullSecond1Display" Data="{StaticResource Digit0}"
|
||||
Fill="White"
|
||||
Width="120" Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,20,0"/>
|
||||
<Path x:Name="FullSecond2Display" Data="{StaticResource Digit0}"
|
||||
Fill="White"
|
||||
Width="120" Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="0,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- 退出提示 -->
|
||||
<TextBlock Text="点击屏幕或按ESC键退出全屏"
|
||||
FontSize="16"
|
||||
Foreground="Gray"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0,0,0,50"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Timers;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
/// <summary>
|
||||
/// 全屏计时器窗口
|
||||
/// </summary>
|
||||
public partial class FullscreenTimerWindow : Window
|
||||
{
|
||||
private SeewoStyleTimerWindow parentWindow;
|
||||
private System.Timers.Timer updateTimer;
|
||||
|
||||
public FullscreenTimerWindow(SeewoStyleTimerWindow parent)
|
||||
{
|
||||
InitializeComponent();
|
||||
parentWindow = parent;
|
||||
|
||||
// 设置窗口位置和大小
|
||||
this.Left = 0;
|
||||
this.Top = 0;
|
||||
this.Width = SystemParameters.PrimaryScreenWidth;
|
||||
this.Height = SystemParameters.PrimaryScreenHeight;
|
||||
|
||||
// 启动更新定时器
|
||||
updateTimer = new System.Timers.Timer(100); // 100ms更新一次
|
||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||
updateTimer.Start();
|
||||
}
|
||||
|
||||
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (parentWindow != null && parentWindow.IsTimerRunning)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
UpdateTimeDisplay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTimeDisplay()
|
||||
{
|
||||
if (parentWindow == null) return;
|
||||
|
||||
// 获取剩余时间
|
||||
var remainingTime = parentWindow.GetRemainingTime();
|
||||
if (remainingTime.HasValue)
|
||||
{
|
||||
var timeSpan = remainingTime.Value;
|
||||
int hours = (int)timeSpan.TotalHours;
|
||||
int minutes = timeSpan.Minutes;
|
||||
int seconds = timeSpan.Seconds;
|
||||
|
||||
// 更新小时显示
|
||||
SetDigitDisplay("FullHour1Display", hours / 10);
|
||||
SetDigitDisplay("FullHour2Display", hours % 10);
|
||||
|
||||
// 更新分钟显示
|
||||
SetDigitDisplay("FullMinute1Display", minutes / 10);
|
||||
SetDigitDisplay("FullMinute2Display", minutes % 10);
|
||||
|
||||
// 更新秒显示
|
||||
SetDigitDisplay("FullSecond1Display", seconds / 10);
|
||||
SetDigitDisplay("FullSecond2Display", seconds % 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDigitDisplay(string pathName, int digit)
|
||||
{
|
||||
var path = this.FindName(pathName) as Path;
|
||||
if (path != null)
|
||||
{
|
||||
string resourceKey = $"Digit{digit}";
|
||||
var geometry = this.FindResource(resourceKey) as Geometry;
|
||||
if (geometry != null)
|
||||
{
|
||||
path.Data = geometry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// 点击屏幕退出全屏
|
||||
ExitFullscreen();
|
||||
}
|
||||
|
||||
private void Window_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
// 按ESC键退出全屏
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
ExitFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
private void ExitFullscreen()
|
||||
{
|
||||
// 恢复主窗口
|
||||
if (parentWindow != null)
|
||||
{
|
||||
parentWindow.Show();
|
||||
parentWindow.Activate();
|
||||
parentWindow.WindowState = WindowState.Normal;
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
// 清理资源
|
||||
if (updateTimer != null)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
updateTimer.Dispose();
|
||||
}
|
||||
base.OnClosed(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -555,19 +555,6 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void Fullscreen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (WindowState == WindowState.Normal)
|
||||
{
|
||||
WindowState = WindowState.Maximized;
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void PlayTimerSound()
|
||||
{
|
||||
try
|
||||
@@ -1014,5 +1001,20 @@ namespace Ink_Canvas
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void Fullscreen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowFullscreenTimer();
|
||||
}
|
||||
|
||||
private void ShowFullscreenTimer()
|
||||
{
|
||||
// 创建全屏计时器窗口
|
||||
var fullscreenWindow = new FullscreenTimerWindow(this);
|
||||
fullscreenWindow.Show();
|
||||
|
||||
// 隐藏主窗口
|
||||
this.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user