简体   繁体   English

使用计时器显示文本3秒钟?

[英]Using a timer to display text for 3 seconds?

Is it possible to use a timer to show text in a label for like 3 sec ? 是否可以使用计时器在标签中显示文本3秒钟? FE When you saved something and it was successful, you'd get a text message "success!" FE当您保存某些内容并成功后,您会收到一条短信“成功!”。 for 3 second and then return to the original page. 3秒钟,然后返回原始页面。

Anyone knows how to do this using a label or a messagebox ? 有人知道如何使用标签或消息框来执行此操作吗?

Yes, it s possible... 是的,有可能...

You may start the timer at where you set the text of the label to "succcess" and set it to tick after 3 seconds and then at the timer_ticks event, you may redirect to the page you want. 您可以在将标签文本设置为“成功”并将其设置为3秒钟后打勾的地方启动计时器,然后在timer_ticks事件中,您可以重定向到所需的页面。

Edit : the code to start the timer - This is a simple windows form having one button and one label 编辑 :启动计时器的代码-这是一个具有一个按钮和一个标签的简单Windows窗体

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();
    }
}

sure, that is possible. 当然,那是可能的。 your going to want to do it with javascript/jquery on the client side to avoid a page refresh, i am thinking. 我想在客户端使用javascript / jquery来做到这一点,以避免页面刷新。 here is a link to how to run javascript on a timer. 这是如何在计时器上运行javascript 的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM