I'm trying to make a form invisible for x amount of time in c#. Any ideas?
Thanks, Jon
BFree has posted similar code in the time it took me to test this, but here's my attempt:
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;
Quick and dirty solution taking advantage of closures. No Timer
required!
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();
}
Example:
// Makes form invisible for 5 seconds.
Invisibilize(new TimeSpan(0, 0, 5));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With