需要标签lblInfo显示内容3秒:
调用DisplayInfo(),将需要显示的字符串作为参数传入
private void DisplayInfo(string lblstring)
{
if (lblInfo.Visible == true)
{
if (!lblstring.Equals(lblInfo.Text))
{
lblInfo.Text = lblstring;
DateTime infoTime = DateTime.Now;
}
}
else
{
lblInfo.Text = lblstring;
infoTime = DateTime.Now;
DateTime lblInfo.Visible = true;
}
}
定时器
private void Timelblinfo_Tick(object sender, EventArgs e)
{
if ((DateTime.Now - infoTime).TotalSeconds > 3)
{
lblInfo.Text = "";
lblInfo.Visible = false;
}
}