我怎样才能显示一个表格之后代码运行? (麻烦与"所示" ;.) [英] How can I get code to run after a form is shown? (Trouble with "Shown".)
本文介绍了我怎样才能显示一个表格之后代码运行? (麻烦与"所示" ;.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我觉得所示
将是答案。但似乎并不是所有的控制都是平等的。 。一个面板的是的立即显示,同时,一个标签 - 不是
I thought Shown
would be the answer. But it seems that not all controls are equal. A panel is shown immediately, while a label – not.
我有以下代码:
public partial class Form2 : Form
{
Panel p = new Panel() { BackColor = Color.Green };
Label l = new Label() { Text = "abc", Location = new Point(0, 100) };
public Form2()
{
Controls.Add(p);
Controls.Add(l);
Shown += new EventHandler(Form2_Shown);
}
void Form2_Shown(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000);
}
}
其中,最初,显示了这一点:
Which, initially, shows this:
2秒后 - 这样的:
And after 2 seconds - this:
所以,我怎么之后的第二图像运行的代码?
So how do I run code after "the second image"?
推荐答案
添加以下的事件处理程序的开头:
Add the following at the beginning of the event handler:
this.Update();
这篇关于我怎样才能显示一个表格之后代码运行? (麻烦与"所示" ;.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文