为Setting窗口添加定时器功能,每秒触发一次,仅在非设计模式且窗口显示时启动
This commit is contained in:
@@ -11,9 +11,53 @@ namespace JoyD.Windows.CS
|
||||
{
|
||||
public partial class Setting : Form
|
||||
{
|
||||
// 创建并显示检测配置窗口
|
||||
public static Setting Form = new Setting();
|
||||
|
||||
// 定时器字段
|
||||
private Timer _timer;
|
||||
|
||||
public Setting()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// 初始化定时器
|
||||
_timer = new Timer();
|
||||
_timer.Interval = 1000; // 1秒 = 1000毫秒
|
||||
_timer.Tick += Timer_Tick;
|
||||
|
||||
// 注册窗口事件
|
||||
this.Shown += Setting_Shown;
|
||||
this.FormClosing += Setting_FormClosing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口显示时启动定时器
|
||||
/// </summary>
|
||||
private void Setting_Shown(object sender, EventArgs e)
|
||||
{
|
||||
// 仅在非设计模式下启动定时器
|
||||
if (!DesignMode)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口关闭时停止定时器
|
||||
/// </summary>
|
||||
private void Setting_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定时器每秒触发的事件处理方法
|
||||
/// </summary>
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
// 这里可以添加每秒需要执行的代码
|
||||
// 例如:更新界面数据、检查状态等
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user