Reputation: 41128
How can I have a label saying: "Registry updates correctly" and then have it disappear after about 2 seconds?
I'm guessing by modifying the .Visible property, but I can't figure it out.
Upvotes: 1
Views: 7491
Reputation: 11
Well if you don't mind the user not being able to do anything for 2 seconds, you could just call Thread.Sleep(2000). If they're just waiting for the update anyhow, it's not much of a difference. Lot less code.
Upvotes: 0
Reputation: 2199
Use the Timer class, but jazz it up so that it can call a method when the Tick event is fired. This is done by creating a new class that inherits from the Timer class. Below is the form code which has a single button control (btnCallMetLater).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DemoWindowApp
{
public partial class frmDemo : Form
{
public frmDemo()
{
InitializeComponent();
}
private void btnCallMeLater_Click(object sender, EventArgs e)
{
MethodTimer hide = new MethodTimer(hideButton);
MethodTimer show = new MethodTimer(showButton);
hide.Interval = 1000;
show.Interval = 5000;
hide.Tick += new EventHandler(t_Tick);
show.Tick += new EventHandler(t_Tick);
hide.Start(); show.Start();
}
private void hideButton()
{
this.btnCallMeLater.Visible = false;
}
private void showButton()
{
this.btnCallMeLater.Visible = true;
}
private void t_Tick(object sender, EventArgs e)
{
MethodTimer t = (MethodTimer)sender;
t.Stop();
t.Method.Invoke();
}
}
internal class MethodTimer:Timer
{
public readonly MethodInvoker Method;
public MethodTimer(MethodInvoker method)
{
Method = method;
}
}
}
Upvotes: 4
Reputation:
You need to setup Timer object and in on timer event hide Your label by setting Visible to false.
Timer class: http://msdn.microsoft.com/en-us/library/system.timers.timer(VS.71).aspx
Upvotes: 1
Reputation: 300489
Create a System.Forms.Timer, with a duration of 2 seconds. Wireup up an event handler to the Tick event and in the handler, set the label's visible property to false (and disable the Timer)
Upvotes: 1
Reputation: 7347
when you set your label, you can make a timer that times out after 2 or 3 seconds that calls a function to hide your label.
Upvotes: 5