How can I have a label saying: "Registry updates correctly" and then have it dissapear after about 2 seconds?
I'm guessing by modifying the .Visible property, but I can't figure it out.
How can I have a label saying: "Registry updates correctly" and then have it dissapear after about 2 seconds?
I'm guessing by modifying the .Visible property, but I can't figure it out.
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.
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)
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%28VS.71%29.aspx
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;
}
}
}