使用定时器3秒钟显示文本? [英] Using a timer to display text for 3 seconds?

查看:223
本文介绍了使用定时器3秒钟显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用一个计时器来显示标签中的文本样3秒?
F.E.当你保存的东西,它是成功的,你会得到一个短信成功了! 3秒钟,然后返回到原来的页

Is it possible to use a timer to show text in a label for like 3 sec ? F.E. When you saved something and it was successful, you'd get a text message "success!" for 3 second and then return to the original page.

任何人都知道如何使用一个标签或一个消息要做到这一点?

Anyone knows how to do this using a label or a messagebox ?

推荐答案

是的,S可能...

您可以开始在您设定的标签为成功的情况下的文定时器,并将其设置在3秒后打勾,然后在timer_ticks时,您可能会重定向到你想要的页面。

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.

修改:在code启动计时器 - 这是一个简单的Windows形成一个按钮和一个标签

Edit: the code to start the timer - This is a simple windows form having one button and one label

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

这篇关于使用定时器3秒钟显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆