等待表单加载完成 [英] Wait until form is finished loading

查看:42
本文介绍了等待表单加载完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有某种布尔值可以用来检查表单实例是否已加载,或者等待表单加载?

Is there some sort of boolean that I can use to check whether the instance of a form is loaded, or otherwise wait until the form is loaded?

例如:

While(form_loaded == false) {
  Try {
    //do something
  }
  catch {
  }//do try catch so code won't barf
}

我不断收到以下异常:

System.InvalidOperationException"类型的第一次机会异常发生在 System.Windows.Forms.dll 中

A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

System.Windows.Forms.dll 中发生类型为System.InvalidOperationException"的未处理异常

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

附加信息:在创建窗口句柄之前,不能在控件上调用 InvokeBeginInvoke.

Additional information: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

这就是我所担心的.

另外,如果需要更详细的解释,我可以尝试发布一些代码和/或更多输出调试信息.

Additionally if a more detailed explanation is needed I can try to post some code and/or some more output debugging information.

推荐答案

尝试像这样使用显示的事件

try to use the shown event something like this

 public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Shown += new System.EventHandler(this.Form1_Shown);
    }

    private void Form1_Shown(object sender, EventArgs e)
    {

    }
}

希望能帮到你

这篇关于等待表单加载完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆