简体   繁体   English

C#显示文本框几秒钟

[英]C# Display a TextBox for a few seconds

I am developing an application for Windows CE using Visual Studio 2008 where I need to display a TextBox for a few seconds like a "Success!" 我正在使用Visual Studio 2008开发适用于Windows CE的应用程序,我需要像“成功!”一样显示文本框几秒钟。 pop-up message you see in some programs. 您在某些程序中看到的弹出消息。

public partial class Form1 : Form
{
    int s;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (s == 1)
        {
            textBox1.Show();
            textBox1.Text = "Success!";
        }
        else
        {
            textBox1.Show();
            textBox1.Text = "Try Again!";
        }

    }
}

Considering that I am using a .NET 3.5 Compact Framework which apparently does not support System.Windows.Forms.Timer . 考虑到我使用的是.NET 3.5 Compact Framework,它显然不支持System.Windows.Forms.Timer Any solution? 有什么办法吗?

You probably want to use the timer class 您可能要使用计时器类

Provides a mechanism for executing a method at specified intervals. 提供一种以指定间隔执行方法的机制。 This class cannot be inherited. 这个类不能被继承。

Timer t = new Timer();
t.Interval = 1000;
timer1.Enabled = true;
timer1.Tick += new System.EventHandler(OnTimerEvent);

Remark : 备注

Use a TimerCallback delegate to specify the method you want the Timer to execute. 使用TimerCallback委托指定您希望计时器执行的方法。 The timer delegate is specified when the timer is constructed, and cannot be changed. 计时器委托是在构造计时器时指定的,不能更改。 The method does not execute on the thread that created the timer; 该方法不在创建计时器的线程上执行; it executes on a ThreadPool thread supplied by the system. 它在系统提供的ThreadPool线程上执行。

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

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