C#显示一个TextBox几秒钟

dav*_*nog 0 c# compact-framework windows-ce .net-3.5 visual-studio-2008

我正在使用Visual Studio 2008开发一个Windows CE应用程序,我需要在几秒钟内显示一个TextBox,就像"成功!" 您在某些程序中看到的弹出消息.

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!";
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

考虑到我使用的.NET 3.5 Compact Framework显然不支持System.Windows.Forms.Timer.有解决方案吗

Rah*_*thi 5

您可能想要使用计时器类

提供以指定间隔执行方法的机制.这个类不能被继承.

Timer t = new Timer();
t.Interval = 1000;
timer1.Enabled = true;
timer1.Tick += new System.EventHandler(OnTimerEvent);
Run Code Online (Sandbox Code Playgroud)

备注:

使用TimerCallback委托指定希望Timer执行的方法.定时器委托是在构造定时器时指定的,不能更改.该方法不会在创建计时器的线程上执行; 它在系统提供的ThreadPool线程上执行.