开发者

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 ? F.E. When you saved som开发者_如何转开发ething 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 ?


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.

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


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. here is a link to how to run javascript on a timer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜