想在一个窗体中点击按钮后文本框间隔显示1-10程序如下:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 10; i++)
{
textBox1.Text = i.ToString();
Thread.Sleep(100);
}
}
}
}问题:
等待时间后文本框只显示了10,1-9都没有显示,不知何故,请解答下,多谢
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 10; i++)
{
textBox1.Text = i.ToString();
Thread.Sleep(100);
}
}
}
}问题:
等待时间后文本框只显示了10,1-9都没有显示,不知何故,请解答下,多谢
解决方案 »
- 请教各位大侠sql2005中的一个查询语句该怎么写请大家帮忙~谢谢
- 版主求教 急·······
- (100分)求QQSMTP邮件发送及QQ空间发帖程序(在线等)
- 请高手指点下c#浏览器跳转默认浏览器问题
- 运算符“+”无法应用于“double[]”和“int”类型的操作数
- 关于正则表达式
- DataSet类型转换
- 关于文本框的问题
- C#如何编码实现删除文件夹里面的文件呢?
- C#中如何控制音量
- 利用WMI获取笔记本的DesignCapacity信息为什么总是为null啊
- C#能开发网吧管理软件吗?刷卡管理的那种 如果都要在客户端安Net framework的话,人家把Net framework给你删了,或客户端找到给你破了,不是
{
StringBuilder sb = new StringBuilder(30);
for (int i = 1; i <= 10; i++)
{
sb.Append(i.ToString());
sb.Append(",");
Thread.Sleep(100);
}
textBox1.Text = sb.ToString();
}
改成
textBox1.Text+= i.ToString();
{
for (int i = 1; i <= 10; i++)
{
textBox1.Text = i.ToString();
Application.DoEvents();//加这句话
Thread.Sleep(100);
}
}
for (int i = 1; i <= 10; i++)
textBox1.Text += i.ToString();
少了+号,在字符串操作中,+号表示连接
是这样的
textbox显示1,延时后显示2,延时后显示3,。。显示10INTTNY是对的,加上Application.DoEvents();后就可以了
能不能说说,Application.DoEvents()的意思啊,不明白