![](/img/trans.png)
[英]How can I wait Until a Form Handle Has Been Created Before Using Its' Components?
[英]How can I make a form's controls not load until at least the frame of the form has been displayed?
我有一个C#Winforms表单,其中包含大量的自定义控件,需要大约10秒钟的加载时间。 现在,当我单击菜单项以打开表单时,菜单冻结10秒钟,然后弹出该表单以供使用。 我要执行的操作如下:单击适当的菜单项打开我的表单后,我想立即显示该表单,但可能背景只有红色且没有控件。 然后,表单可以开始尝试加载我的所有控件。 这样,用户可以看到他们的鼠标单击打开了新表单,并且看起来整个应用程序都没有冻结。 不能将其移动到新线程。
您是否尝试过将用户控件放在单独的用户控件中,然后在Shown事件中实例化它,然后将其添加到表单中。
即像这样的东西
表格1
public partial class Form1 : Form
{
UserControl1 usr;
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
usr = new UserControl1();
usr.Dock = DockStyle.Fill;
panel1.Controls.Add(usr);
}
}
UserControl1
public partial class UserControl1 : UserControl
{
public UserControl1()
{
System.Threading.Thread.Sleep(10000);
InitializeComponent();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.