feat: 优化休息提醒弹窗,去除白框闪现
This commit is contained in:
39
RestForm.cs
39
RestForm.cs
@@ -12,6 +12,18 @@ namespace TimerApp
|
|||||||
|
|
||||||
public event EventHandler? SkipRequested;
|
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()
|
public RestForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -29,10 +41,11 @@ namespace TimerApp
|
|||||||
// Form 设置
|
// Form 设置
|
||||||
//
|
//
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
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.TopMost = true;
|
||||||
this.BackColor = System.Drawing.Color.Black;
|
this.BackColor = System.Drawing.Color.Black;
|
||||||
this.Opacity = 0.90; // 90% 不透明度
|
this.Opacity = 0; // 初始隐藏,避免闪烁
|
||||||
this.ShowInTaskbar = false;
|
this.ShowInTaskbar = false;
|
||||||
this.Name = "RestForm";
|
this.Name = "RestForm";
|
||||||
this.Text = "Rest Now";
|
this.Text = "Rest Now";
|
||||||
@@ -104,6 +117,28 @@ namespace TimerApp
|
|||||||
CenterControls();
|
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)
|
private void RestForm_Resize(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CenterControls();
|
CenterControls();
|
||||||
|
|||||||
Reference in New Issue
Block a user