当我的表单在 C#(.Net Compact Framework)中完全加载时发出通知?
我的应用程序中有一个表单,我想在表单
完全加载时进行一些处理,但加载完成后没有可以绑定的事件或内容。
有谁有任何想法,我该怎么做?
I have a form in my application and I want to do some processing when my form has been
Fully loaded but I have no event or something which I can bind to when load is finished.
Does anyone has any idea, how can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
“满载”到底是什么意思?您的意思是“加载”事件已成功进行?
您可以这样做:
但是如果您的意思是“完全加载”,则“表单已加载并显示”,您也需要重写“OnPaint”方法。
What exaclty mean "fully loaded" ? Do you mean, the "Load" event was successfully proceeded?
You can do this:
But if you mean "fully loaded" the "form is loaded AND shown" you need override the "OnPaint" method too.
我认为
OnLoad
事件并不是您真正想要的,因为它发生在表单显示之前。您可以将Application.Idle
与OnLoad
一起使用来创建OnLoaded
事件:I think the
OnLoad
event isn't really what you want, as it occurs before the form is displayed. You can useApplication.Idle
withOnLoad
to make anOnLoaded
event though:您应该能够使用 OnLoad 事件。
http://msdn.microsoft.com/en -us/library/system.windows.forms.form.onload.aspx
you should be able to use the OnLoad event.
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onload.aspx
我的方法类似于 TcKs 接受的答案。
我面临的问题是,我有一个用于一组控件的事件处理程序,这些控件通过事件处理程序在面板内移动控件来响应 VisibleChanged。问题是(当然),首次加载表单时可见性会发生变化 - 但在 .Load() 事件之后。
我为 Form: 创建并设置了一个 bool 值,
然后将以下行添加到 Form_Load() 中
,其中 VisibleChanged() 事件处理程序的第一行为:
简洁且实用。
My approach is similar to the accepted answer from TcKs.
The problem I faced was that I had an event handler for a group of controls that responded to VisibleChanged with the event handler moving controls about within a Panel. Trouble was (of course) that the Visibility changes when the form is first loaded - but after the .Load() event.
I created and set a bool value for the Form:
and then added the following line to the Form_Load()
with the first line of my VisibleChanged() event handler as:
Succinct and functional.
您可以使用表单的
Load
事件。在表单的构造函数中编写以下行,然后编写以下方法,您可以在其中执行一些操作。
You can use the
Load
event of the form. In the constructor of your Form write following lineand then write the following method in which you can do some stuff.