相关疑难解决方法(0)

在WinForm上运行数字时钟

嗨,我必须设计一个具有简单文本框的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)

c# timer winforms

6
推荐指数
1
解决办法
3万
查看次数

Windows窗体上的时钟没有轮询?

我需要在表单上显示当前时间和秒数.我的时钟必须显示秒,我担心性能.

  1. 有没有轮询的方法?(某些系统事件或什么?)
  2. 如果没有没有轮询的方法 - 我是否应该Date().getTime()在我的计时器嘀嗒事件中获取当前时间?

.net c# .net-3.5 winforms

0
推荐指数
1
解决办法
298
查看次数

标签 统计

c# ×2

winforms ×2

.net ×1

.net-3.5 ×1

timer ×1