CodePudding user response:
The form to add a Timer control,CodePudding user response:
private System. Windows. Forms. The Timer timer1=null;
Int I=5;
Public _click ()
{
InitializeComponent ();
Timer1=new System. Windows. Forms. The Timer ();
Timer1. Interval=1000;
This. The timer1. Tick +=new System. EventHandler (enclosing timer1_Tick);
}
Private void button1_Click (object sender, EventArgs e)
{
Timer1. Enabled=true;
Timer1. Start ();
}
Private void timer1_Tick (object sender, EventArgs e)
{
If (I & gt; 0)
{
This. The textBox1. Text=i.T oString ();
i--;
}
The else
{
Timer1. Enabled=false;
Timer1. Stop ();
}
}
CodePudding user response:
Thread.sleep is directly suspend threads, you pause the UI Thread, the system can't update the interface,CodePudding user response:
After each Sleep plus Applicaiton. DoEvents () to force rendering UICodePudding user response: