private void button_click(object sender, EventArgs e)
{
   textbox1.Text = "Running...";
   //运行一些颇费时间的运算
     ...
   textbox1.Text = "Done.";
}
但我发现第一句没有显示出来, 那个"running.."没有显示, 当运行完后直接就显示"Done."了, 请问如何让第一句能够发挥作用?

解决方案 »

  1.   

    private void button_click(object sender, EventArgs e)
    {
       textbox1.Text = "Running...";
       Application.DoEvents();
       //运行一些颇费时间的运算
         ...
       textbox1.Text = "Done.";
    }
      

  2.   


    你那个在实质上已经显示过了,只是更改的速度太快你没有看到罢了,你需要看到一个渐变的过程,你可以将操作的时间放慢一点private void button_click(object sender, EventArgs e)
    {
       textbox1.Text = "Running...";
       //线程休息一段时间
       System.Threading.Thread.Sleep(5 * 1000);
         ...
       textbox1.Text = "Done.";
    }
      

  3.   

    private void button_click(object sender, EventArgs e)
    {
       textbox1.Text = "Running...";
       Application.DoEvents();
       //运行一些颇费时间的运算
         ...
       textbox1.Text = "Done.";
    }
    或者用委托,也可以解决。建议开启线程进行较长时间运算,这样你的界面不会假死,当然线程里要访问、设置某个控件属性必须使用委托,否则编译不成功。