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();