等待表单加载完成

编程入门 行业动态 更新时间:2024-10-27 08:27:27
本文介绍了等待表单加载完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 11:28:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1115292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   加载

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!