【发布时间】:2013-02-20 13:21:54
【问题描述】:
是否可以使用计时器在标签中显示文本 3 秒? F.E. 当您保存某些内容并成功时,您会收到一条短信“成功!” 3秒后返回原页面。
任何人都知道如何使用标签或消息框来做到这一点?
【问题讨论】:
是否可以使用计时器在标签中显示文本 3 秒? F.E. 当您保存某些内容并成功时,您会收到一条短信“成功!” 3秒后返回原页面。
任何人都知道如何使用标签或消息框来做到这一点?
【问题讨论】:
是的,有可能……
您可以在将标签文本设置为“成功”的位置启动计时器,并将其设置为 3 秒后滴答,然后在 timer_ticks 事件中,您可以重定向到您想要的页面。
编辑:启动计时器的代码 - 这是一个简单的窗口窗体,有一个按钮和一个标签
public partial class Form1 : Form
{
//Create the timer
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
//Set the timer tick event
myTimer.Tick += new System.EventHandler(myTimer_Tick);
}
private void button1_Click(object sender, EventArgs e)
{
//Set the timer tick interval time in milliseconds
myTimer.Interval = 1000;
//Start timer
myTimer.Start();
}
//Timer tick event handler
private void myTimer_Tick(object sender, System.EventArgs e)
{
this.label1.Text = "Successful";
//Stop the timer - if required
myTimer.Stop();
}
}
【讨论】:
当然,这是可能的。你会想在客户端使用 javascript/jquery 来避免页面刷新,我在想。 here is a link 如何在计时器上运行 javascript。
【讨论】: