给个思路 没做过winform 在winform 中 我点一个按钮 给一个TextBox 赋值可能按钮事件中的处理需要很长时间,比如说10分钟,我需要向TextBox输出处理信息。现在问题是,按钮事件执行完毕后TextBox才会显示输出的信息,我想做到事件处理的时候就逐行输出到TextBox 不知道我表达明白没? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 赋值完毕加一句Application.DoEvents(); 如果用线程处理的话,那你更新控件的时候得用委托来做Google "invokerequired" 表达基本明白我随便给你发个例子,这是我当时遇到这个问题写的一个Demo,呵呵 private MyMethod my; static Form2 f2 = null; static Timer timer = null; static bool result = false; public Form1() { timer = new Timer(); timer.Interval = 10; timer.Tick += new EventHandler(timer_tick); timer.Start(); InitializeComponent(); my = new MyMethod(method); } private int method() { System.Threading.Thread.Sleep(5000); return 100; } private void MethodComplete(IAsyncResult iar) { if (iar == null) return; if (tb5.InvokeRequired) { write writeIntoTB = new write(RefreshTB); tb5.BeginInvoke(writeIntoTB, (iar.AsyncState as MyMethod).EndInvoke(iar).ToString()); } else { RefreshTB((iar.AsyncState as MyMethod).EndInvoke(iar).ToString()); } result = true; } private void RefreshTB(string s) { tb5.Clear(); tb5.Text = s; } private void bt5_Click(object sender, EventArgs e) { result = false; IAsyncResult iar = my.BeginInvoke(MethodComplete, my); f2 = new Form2(); f2.ShowDialog(); } private void timer_tick(object sender, EventArgs e) { if (result) { if (f2 != null) { f2.Close(); } } } 新手求教育!!! 服务器场景管理问题 【讨论】突然的一个想法——windows 复制\粘贴 功能增强 设定表格中行的字的颜色不同 c# ListView问题 选中记录得值的问题 visual studio 2003/2005中有没有提供java代码转化为c#代码的工具?在那能得到这种工具? Excel ——〉htm的问题 如何让一个按钮对应多个处理情况? C# 全局快捷键的问题 组合算法 能够给个文件操作示例么? 十六进制与十进制的对应关系函数问题 js验证asp.net控件
Application.DoEvents();
Google "invokerequired"
static Form2 f2 = null;
static Timer timer = null;
static bool result = false;
public Form1()
{
timer = new Timer();
timer.Interval = 10;
timer.Tick += new EventHandler(timer_tick);
timer.Start();
InitializeComponent();
my = new MyMethod(method);
}
private int method()
{
System.Threading.Thread.Sleep(5000);
return 100;
}
private void MethodComplete(IAsyncResult iar)
{
if (iar == null) return;
if (tb5.InvokeRequired)
{
write writeIntoTB = new write(RefreshTB);
tb5.BeginInvoke(writeIntoTB, (iar.AsyncState as MyMethod).EndInvoke(iar).ToString());
}
else
{
RefreshTB((iar.AsyncState as MyMethod).EndInvoke(iar).ToString());
}
result = true;
}
private void RefreshTB(string s)
{
tb5.Clear();
tb5.Text = s;
}
private void bt5_Click(object sender, EventArgs e)
{
result = false;
IAsyncResult iar = my.BeginInvoke(MethodComplete, my);
f2 = new Form2();
f2.ShowDialog();
}
private void timer_tick(object sender, EventArgs e)
{
if (result)
{
if (f2 != null)
{
f2.Close();
}
}
}