Mat*_*ton 16
BFree在我测试时发布了类似的代码,但这是我的尝试:
this.Hide();
var t = new System.Windows.Forms.Timer
{
Interval = 3000 // however long you want to hide for
};
t.Tick += (x, y) => { t.Enabled = false; this.Show(); };
t.Enabled = true;
Run Code Online (Sandbox Code Playgroud)
快速而肮脏的解决方案利用封闭.无需定时器!
private void Invisibilize(TimeSpan Duration)
{
(new System.Threading.Thread(() => {
this.Invoke(new MethodInvoker(this.Hide));
System.Threading.Thread.Sleep(Duration);
this.Invoke(new MethodInvoker(this.Show));
})).Start();
}
Run Code Online (Sandbox Code Playgroud)
例:
//使表单隐藏5秒钟
Invisibilize(new TimeSpan(0,0,5));