问题描述
限时送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
附加信息:在创建窗口句柄之前,不能在控件上调用 Invoke
或 BeginInvoke
.
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:关键词]
发布评论