improve:计时器
This commit is contained in:
@@ -31,6 +31,8 @@ namespace Ink_Canvas
|
||||
updateTimer = new System.Timers.Timer(100);
|
||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||
updateTimer.Start();
|
||||
|
||||
parentWindow.TimerCompleted += ParentWindow_TimerCompleted;
|
||||
}
|
||||
|
||||
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
@@ -70,6 +72,14 @@ namespace Ink_Canvas
|
||||
SetDigitDisplay("FullSecond2Display", seconds % 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void ParentWindow_TimerCompleted(object sender, EventArgs e)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
this.Close();
|
||||
});
|
||||
}
|
||||
|
||||
private void SetDigitDisplay(string pathName, int digit)
|
||||
{
|
||||
@@ -116,6 +126,11 @@ namespace Ink_Canvas
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (parentWindow != null)
|
||||
{
|
||||
parentWindow.TimerCompleted -= ParentWindow_TimerCompleted;
|
||||
}
|
||||
|
||||
// 清理资源
|
||||
if (updateTimer != null)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,9 @@ namespace Ink_Canvas
|
||||
isTimerRunning = false;
|
||||
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
||||
PlayTimerSound();
|
||||
|
||||
TimerCompleted?.Invoke(this, EventArgs.Empty);
|
||||
HandleTimerCompletion();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -96,6 +99,8 @@ namespace Ink_Canvas
|
||||
private MinimizedTimerWindow minimizedWindow;
|
||||
private DateTime lastActivityTime;
|
||||
private bool isFullscreenMode = false;
|
||||
private FullscreenTimerWindow fullscreenWindow;
|
||||
public event EventHandler TimerCompleted;
|
||||
|
||||
// 最近计时记录
|
||||
private string recentTimer1 = "--:--";
|
||||
@@ -1120,11 +1125,32 @@ namespace Ink_Canvas
|
||||
isFullscreenMode = true;
|
||||
|
||||
// 创建全屏计时器窗口
|
||||
var fullscreenWindow = new FullscreenTimerWindow(this);
|
||||
fullscreenWindow = new FullscreenTimerWindow(this);
|
||||
fullscreenWindow.Show();
|
||||
|
||||
// 隐藏主窗口
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
private void HandleTimerCompletion()
|
||||
{
|
||||
if (minimizedWindow != null)
|
||||
{
|
||||
minimizedWindow.Close();
|
||||
minimizedWindow = null;
|
||||
this.Show();
|
||||
this.Activate();
|
||||
this.WindowState = WindowState.Normal;
|
||||
}
|
||||
else if (fullscreenWindow != null)
|
||||
{
|
||||
fullscreenWindow.Close();
|
||||
fullscreenWindow = null;
|
||||
isFullscreenMode = false;
|
||||
this.Show();
|
||||
this.Activate();
|
||||
this.WindowState = WindowState.Normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user