using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Threading;namespace _ { public partial class Form1 : Form { public Form1() { InitializeComponent(); for (int i = 1; i <= 100; i++) { this.label1.Text = i.ToString(); Thread.Sleep(100); } } } }我这个怎么全部结束才弹出窗口啊,求解
不用按钮就写在Form_Load中,加载窗体时触发。
使用Thread.Sleep(1000);不会出现数字跳动。还是放在timer控件中写代码吧
看了上面的代码。 凡是有sleep 的建义不要用! 我建义用timer ,的tick
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading;namespace test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int time = 0; int i = 1; private void Change() { i++; label1.Text = i.ToString(); } private void timer1_Tick(object sender, EventArgs e) { time++; if (time % 10 == 0) { Change(); } if (i >= 100) { timer1.Stop(); } } } }
this.lbl.Text=i;
Thread.Sleep(1000);
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;namespace _
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 1; i <= 100; i++)
{
this.label1.Text = i.ToString();
Thread.Sleep(100);
}
}
}
}我这个怎么全部结束才弹出窗口啊,求解
凡是有sleep 的建义不要用!
我建义用timer ,的tick
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int time = 0;
int i = 1;
private void Change()
{
i++;
label1.Text = i.ToString();
} private void timer1_Tick(object sender, EventArgs e)
{
time++;
if (time % 10 == 0)
{
Change();
}
if (i >= 100)
{
timer1.Stop();
}
}
}
}