4

我有一个 WinForms 程序,其中包含 a 、buttonastatusStrip和 a toolStripStatusLabelstatusStrip如果我单击按钮并运行:

private void button1_Click(object sender, EventArgs e)
{
    toolStripStatusLabel1.Text = "Test";

    System.Threading.Thread.Sleep(5000);
}

然后toolStripStatusLabel' 的文本直到线程完成睡眠后才会更新。如何让它立即更新,然后让线程休眠?

4

5 回答 5

6

正如P. Kouvarakis所说,解决方案是:

toolStripStatusLabel1.Text = "Test";
statusStrip1.Update();
于 2017-04-18T14:08:04.800 回答
0

当状态条将 Spring 设置为 true 时,我的状态标签更改未在运行时显示。我将 Spring 设置为 false 并开始显示。

于 2021-02-16T17:06:27.170 回答
0
  1. 您需要添加 StatusStrip 文本标签(作为孩子)(因为您无法使用父组件的文本进行操作),如下所示:

子组件

  1. 当您双击 statusstrip 组件时,您将看到下一个

2ble点击图片

不要在此处添加文本更改代码,因为只有在单击它后才会刷新它(如图所示 - statusStrip1_ItemClicked)所以,任何 statusStrip1.Update(); this.Update(); 等帮不了你。

  1. 如何快速完成。您可以添加if目标条件开始的位置,如下图所示

例子

于 2021-04-08T11:55:25.517 回答
-1
toolStripStatusLabel1.Text = "Test";
Application.DoEvents();
于 2019-07-05T14:27:17.887 回答
-1

最后的解决方案Application.DoEvents()是最好的。Application.DoEvents()必须附加到每个 StatusStrip 更改:

private void SetParseStatus(object sender, ParseStatusChangedEventArgs e)
{
    toolStripProgressBar1.Value = e.Percent;
    Application.DoEvents();
}
于 2019-08-13T16:39:30.183 回答