improve:计时器
This commit is contained in:
@@ -31,6 +31,8 @@ namespace Ink_Canvas
|
|||||||
updateTimer = new System.Timers.Timer(100);
|
updateTimer = new System.Timers.Timer(100);
|
||||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||||
updateTimer.Start();
|
updateTimer.Start();
|
||||||
|
|
||||||
|
parentWindow.TimerCompleted += ParentWindow_TimerCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
|
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
@@ -70,6 +72,14 @@ namespace Ink_Canvas
|
|||||||
SetDigitDisplay("FullSecond2Display", seconds % 10);
|
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)
|
private void SetDigitDisplay(string pathName, int digit)
|
||||||
{
|
{
|
||||||
@@ -116,6 +126,11 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
protected override void OnClosed(EventArgs e)
|
protected override void OnClosed(EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (parentWindow != null)
|
||||||
|
{
|
||||||
|
parentWindow.TimerCompleted -= ParentWindow_TimerCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
// 清理资源
|
// 清理资源
|
||||||
if (updateTimer != null)
|
if (updateTimer != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Ink_Canvas
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
parentWindow = parent;
|
parentWindow = parent;
|
||||||
|
|
||||||
// 设置窗口位置(保持父窗口的位置)
|
// 设置窗口位置
|
||||||
this.Left = parent.Left;
|
this.Left = parent.Left;
|
||||||
this.Top = parent.Top;
|
this.Top = parent.Top;
|
||||||
|
|
||||||
@@ -33,6 +33,8 @@ namespace Ink_Canvas
|
|||||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||||
updateTimer.Start();
|
updateTimer.Start();
|
||||||
|
|
||||||
|
parentWindow.TimerCompleted += ParentWindow_TimerCompleted;
|
||||||
|
|
||||||
// 应用主题
|
// 应用主题
|
||||||
ApplyTheme();
|
ApplyTheme();
|
||||||
}
|
}
|
||||||
@@ -74,6 +76,14 @@ namespace Ink_Canvas
|
|||||||
SetDigitDisplay("MinSecond2Display", seconds % 10);
|
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)
|
private void SetDigitDisplay(string pathName, int digit)
|
||||||
{
|
{
|
||||||
@@ -226,6 +236,11 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
protected override void OnClosed(EventArgs e)
|
protected override void OnClosed(EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (parentWindow != null)
|
||||||
|
{
|
||||||
|
parentWindow.TimerCompleted -= ParentWindow_TimerCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
// 清理资源
|
// 清理资源
|
||||||
if (updateTimer != null)
|
if (updateTimer != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ namespace Ink_Canvas
|
|||||||
isTimerRunning = false;
|
isTimerRunning = false;
|
||||||
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
||||||
PlayTimerSound();
|
PlayTimerSound();
|
||||||
|
|
||||||
|
TimerCompleted?.Invoke(this, EventArgs.Empty);
|
||||||
|
HandleTimerCompletion();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -96,6 +99,8 @@ namespace Ink_Canvas
|
|||||||
private MinimizedTimerWindow minimizedWindow;
|
private MinimizedTimerWindow minimizedWindow;
|
||||||
private DateTime lastActivityTime;
|
private DateTime lastActivityTime;
|
||||||
private bool isFullscreenMode = false;
|
private bool isFullscreenMode = false;
|
||||||
|
private FullscreenTimerWindow fullscreenWindow;
|
||||||
|
public event EventHandler TimerCompleted;
|
||||||
|
|
||||||
// 最近计时记录
|
// 最近计时记录
|
||||||
private string recentTimer1 = "--:--";
|
private string recentTimer1 = "--:--";
|
||||||
@@ -1120,11 +1125,32 @@ namespace Ink_Canvas
|
|||||||
isFullscreenMode = true;
|
isFullscreenMode = true;
|
||||||
|
|
||||||
// 创建全屏计时器窗口
|
// 创建全屏计时器窗口
|
||||||
var fullscreenWindow = new FullscreenTimerWindow(this);
|
fullscreenWindow = new FullscreenTimerWindow(this);
|
||||||
fullscreenWindow.Show();
|
fullscreenWindow.Show();
|
||||||
|
|
||||||
// 隐藏主窗口
|
// 隐藏主窗口
|
||||||
this.Hide();
|
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