嗨,我必须设计一个具有简单文本框的Windows窗体.文本框包含类似文本的计时器(00:00格式).
我想每秒刷新页面,并使文本框的内容相应更改.(就像数字时钟一样,运行一小时!).
我想我需要使用System.Windows.Forms.Timer该类,我已经Timer从ToolBox中删除了一个项目到我的表单.
下一步......我需要使用Thread.Sleep(1000)功能......任何想法?
这是我一直在尝试的代码片段.我知道程序中出错了,这thread.sleep()部分甚至会让我的代码运行更糟.我在ToolBox中尝试了Timer的东西,但无法通过.(当我运行代码时,它成功编译,然后应用程序由于脏For-Loops冻结一小时)帮助!
public partial class Form1 : Form
{
Button b = new Button();
TextBox tb = new TextBox();
//System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
public Form1()
{
b.Click += new EventHandler(b_click);
b.Text = "START";
tb.Text = "00 : 00";
//timer1.Enabled = true;
//timer1.Interval = 1000;
tb.Location = new Point(100, 100);
this.Controls.Add(tb);
this.Controls.Add(b);
InitializeComponent();
}
private void refreshTimer_Tick()
{
for (int i = 0; i < 60; i++)
{
for …Run Code Online (Sandbox Code Playgroud) 简单请求 - 我希望能够在我的WPF应用程序窗口中显示当前时间.那里有免费控制吗?只需要显示时间,没有别的.