improve:计时器

This commit is contained in:
2025-10-12 16:08:36 +08:00
parent 339ebb862e
commit 869dd045af
3 changed files with 58 additions and 2 deletions
@@ -24,7 +24,7 @@ namespace Ink_Canvas
InitializeComponent();
parentWindow = parent;
// 设置窗口位置(保持父窗口的位置)
// 设置窗口位置
this.Left = parent.Left;
this.Top = parent.Top;
@@ -33,6 +33,8 @@ namespace Ink_Canvas
updateTimer.Elapsed += UpdateTimer_Elapsed;
updateTimer.Start();
parentWindow.TimerCompleted += ParentWindow_TimerCompleted;
// 应用主题
ApplyTheme();
}
@@ -74,6 +76,14 @@ namespace Ink_Canvas
SetDigitDisplay("MinSecond2Display", seconds % 10);
}
}
private void ParentWindow_TimerCompleted(object sender, EventArgs e)
{
Application.Current.Dispatcher.Invoke(() =>
{
this.Close();
});
}
private void SetDigitDisplay(string pathName, int digit)
{
@@ -226,6 +236,11 @@ namespace Ink_Canvas
protected override void OnClosed(EventArgs e)
{
if (parentWindow != null)
{
parentWindow.TimerCompleted -= ParentWindow_TimerCompleted;
}
// 清理资源
if (updateTimer != null)
{