控制启动时的初始化延迟

时间:2010-06-07 18:18:03

标签: c# winforms

当我启动应用程序时,我正在使用的控件有一个小的延迟。我可以在绘制控件后显示主要表单吗?

1 个答案:

答案 0 :(得分:1)

尝试订阅表单加载方法中的Application.Idle事件,并在调用后取消订阅。像这样:

public Form()
{
    InitializeComponent();
}

private void Form_Load(object sender, EventArgs e)
{
    Application.Idle += new EventHandler(Application_Idle);
    // any loading prep code here
}

private void Application_Idle(object sender, EventArgs e)
{
    Application.Idle -= new EventHandler(Application_Idle);
    // additional code here, which is executed *after* controls are visible and loaded
}