我试图在c#中使表单在x时间内不可见.有任何想法吗?
谢谢,乔恩
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;
快速而肮脏的解决方案利用封闭.无需定时器!
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(); }
例:
//使表单隐藏5秒钟
Invisibilize(new TimeSpan(0,0,5));