From e597ce1e5c56a874b956dbd5babdd1d8fc5a105e Mon Sep 17 00:00:00 2001 From: Solin Date: Wed, 21 Jan 2026 18:05:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BC=91=E6=81=AF?= =?UTF-8?q?=E6=8F=90=E9=86=92=E5=BC=B9=E7=AA=97=EF=BC=8C=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E7=99=BD=E6=A1=86=E9=97=AA=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RestForm.cs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/RestForm.cs b/RestForm.cs index 2a2c4f1..e80539e 100644 --- a/RestForm.cs +++ b/RestForm.cs @@ -12,6 +12,18 @@ namespace TimerApp public event EventHandler? SkipRequested; + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + // Turn on WS_EX_TOOLWINDOW style bit (0x80) + // 这可以防止窗口出现在 Alt-Tab 列表中,并减少任务栏闪烁风险 + cp.ExStyle |= 0x80; + return cp; + } + } + public RestForm() { InitializeComponent(); @@ -29,10 +41,11 @@ namespace TimerApp // Form 设置 // this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.WindowState = FormWindowState.Maximized; + this.StartPosition = FormStartPosition.Manual; + this.Location = new System.Drawing.Point(-32000, -32000); // 初始位置在屏幕外 this.TopMost = true; this.BackColor = System.Drawing.Color.Black; - this.Opacity = 0.90; // 90% 不透明度 + this.Opacity = 0; // 初始隐藏,避免闪烁 this.ShowInTaskbar = false; this.Name = "RestForm"; this.Text = "Rest Now"; @@ -104,6 +117,28 @@ namespace TimerApp CenterControls(); } + protected override void OnVisibleChanged(EventArgs e) + { + base.OnVisibleChanged(e); + if (this.Visible) + { + // 移回屏幕并最大化 + this.Location = new Point(0, 0); + this.WindowState = FormWindowState.Maximized; + this.Refresh(); + + // 延迟显示,确保布局调整完成 + System.Windows.Forms.Timer t = new System.Windows.Forms.Timer(); + t.Interval = 50; + t.Tick += (s, ev) => { + t.Stop(); + t.Dispose(); + this.Opacity = 0.90; + }; + t.Start(); + } + } + private void RestForm_Resize(object? sender, EventArgs e) { CenterControls();