I have buttons which validate if the user is administrator or not. If the user currently login is not an administrator then label will show as warning message and then hide after a few seconds. I tried using lblWarning.Hide();
and lblWarning.Dispose();
after the warning message, but the problem is, it hides the message before even showing the warning message. This is my code.
private void button6_Click(object sender, EventArgs e)
{
if (txtLog.Text=="administrator")
{
Dialog();
}
else
{
lblWarning.Text = "This action is for administrator only.";
lblWarning.Hide();
}
}
You're going to want to "hide" it with a Timer
. You might implement something like this:
var t = new Timer();
t.Interval = 3000; // it will Tick in 3 seconds
t.Tick += (s, e) =>
{
lblWarning.Hide();
t.Stop();
};
t.Start();
instead of this:
lblWarning.Hide();
so if you wanted it visible for more than 3 seconds then just take the time you want and multiply it by 1000 because Interval
is in milliseconds.
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