如何在其他依赖形式之前加载frmMain? [英] How to get frmMain to load before other dependent forms?

查看:54
本文介绍了如何在其他依赖形式之前加载frmMain?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个主要形式(frmMain,项目的启动对象)和

其他几个孩子在
frmMain上的大面板中绘制的表单。


在每个表单的Form_Load事件中,加载该表单的弱引用

进入全局哈希表,如下所示:

Dim wr As WeakReference = New WeakReference(Me,False)


如果不是hashTable.Contains(cfrmMain)那么


hashTable.Add(cfrmMain,wr)


结束如果


我在frmMain中也有以下声明,就在设计师代码之后,
每个孩子的
在frmMain面板上绘制的形式:


朋友frmAdmin作为新的frmAdmin


朋友frm任命为新的frmAppointment


朋友frmBilling为新的frmBilling


朋友frmSystem作为新的frmSystem


每个子表单写入frmMain的状态栏在他们的Form_Load

事件中。


问题是,子表单的加载事件在之前触发


frmMain的load事件已经引用了哈希表。


如何在子Form_Load

事件之前完全触发frmMain的Form_Load


火?或者,我怎样才能在孩子面前将frmMain的条目输入hashTable

Form_Load


事件火灾?


除了这个特定的问题,我想找一篇

解释的文章

详细说明当VB应用程序<时,顺序会发生什么br />
推出。


谢谢,


Dean Slindee

My project has a main form (frmMain, the startup object for the project) and
several other "child" forms that are painted within a large panel on
frmMain.

In each form''s Form_Load event, a Weak Reference for that form is loaded
into a global Hash table, like this:

Dim wr As WeakReference = New WeakReference(Me, False)

If Not hashTable.Contains(cfrmMain) Then

hashTable.Add(cfrmMain, wr)

End If

I also have the following declares in frmMain, just after the designer code,
for each "child" form that gets painted inside the panel on frmMain:

Friend frmAdmin As New frmAdmin

Friend frmAppointment As New frmAppointment

Friend frmBilling As New frmBilling

Friend frmSystem As New frmSystem

Each child form writes to the status bar on frmMain in their Form_Load
event.

Problem is, the load events for the child forms are firing before

the load event for frmMain has put a reference into the hash table.

How can I get frmMain''s Form_Load to fire completely before child Form_Load
events

fire? Or, how can I get an entry for frmMain into hashTable before child
Form_Load

events fire?

Above and beyond this specific problem, I would like to find an article that
explains in

great detail exactly what happens in sequence when a VB application is
launched.

Thanks,

Dean Slindee

推荐答案

你好Dean,


感谢你的帖子。据我所知,你面临的问题是你的孩子是什么?在'frmMain之前调用加载方法。

如果有任何误解,请纠正我。


Form.Load事件发生在a之前表单首次显示。

因此,一般来说,启动表单的Load方法将首先调用

。我可以通过以下步骤验证它:


1.创建一个WinForm应用程序。


2.添加一个新表单(Form2)到项目。


3.在每个表单的Load方法中,添加以下代码以显示

消息框。

MessageBox.Show(" Form1_Load")



MessageBox.Show(" Form2_Load")


4.在Form1(启动对象)中声明如下:

朋友frmForm2作为新表格2


5.执行程序,你会注意到Form2_Load ()不会是

,直到你explcitly调用Form2.Show()。


如需进一步研究,请在试图绘画时告诉我

" child"表格到frmMain?我建议你在

frmMain_Load方法的末尾画它们。


希望这会有所帮助。


问候,


HuangTM

微软在线合作伙伴支持

MCSE / MCSD


获取安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有授予任何权利。

Hello Dean,

Thanks for your post. As I understand, the problem you are facing is that
your "child" forms'' Load methods are called before that of the frmMain.
Please correct me if there is any misunderstand.

The Form.Load event occurs before a form is displayed for the first time.
So, generally speaking, the Load method of startup Form will be called
first. I am able to verify it by the following steps:

1. Create a WinForm application.

2. Add a new Form (Form2) to the project.

3. In the Load method of each form, add the following code to display a
message box.
MessageBox.Show("Form1_Load")
or
MessageBox.Show("Form2_Load")

4. Have the following declare in Form1 (the startup object):
Friend frmForm2 As New Form2

5. Execute the program and you will notice that Form2_Load() will not be
called until you explcitly call Form2.Show().

For further research, could you please tell me when you try to paint
"child" Forms to the frmMain? I recommend you paint them at the end of the
frmMain_Load method.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Hello Dean,


感谢您的帖子。据我所知,你面临的问题是你的孩子是什么?在'frmMain之前调用加载方法。

如果有任何误解,请纠正我。


Form.Load事件发生在a之前表单首次显示。

因此,一般来说,启动表单的Load方法将首先调用

。我可以通过以下步骤验证它:


1.创建一个WinForm应用程序。


2.添加一个新表单(Form2)到项目。


3.在每个表单的Load方法中,添加以下代码以显示

消息框。

MessageBox.Show(" Form1_Load")



MessageBox.Show(" Form2_Load")


4.在Form1(启动对象)中声明如下:

朋友frmForm2作为新表格2


5.执行程序,你会注意到Form2_Load ()不会是

,直到你explcitly调用Form2.Show()。


如需进一步研究,请在试图绘画时告诉我

" child"表格到frmMain?我建议你在

frmMain_Load方法的末尾画它们。


希望这会有所帮助。


问候,


HuangTM

微软在线合作伙伴支持

MCSE / MCSD


获取安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有赋予任何权利。

Hello Dean,

Thanks for your post. As I understand, the problem you are facing is that
your "child" forms'' Load methods are called before that of the frmMain.
Please correct me if there is any misunderstand.

The Form.Load event occurs before a form is displayed for the first time.
So, generally speaking, the Load method of startup Form will be called
first. I am able to verify it by the following steps:

1. Create a WinForm application.

2. Add a new Form (Form2) to the project.

3. In the Load method of each form, add the following code to display a
message box.
MessageBox.Show("Form1_Load")
or
MessageBox.Show("Form2_Load")

4. Have the following declare in Form1 (the startup object):
Friend frmForm2 As New Form2

5. Execute the program and you will notice that Form2_Load() will not be
called until you explcitly call Form2.Show().

For further research, could you please tell me when you try to paint
"child" Forms to the frmMain? I recommend you paint them at the end of the
frmMain_Load method.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


" Dean Slindee" < SL ***** @ mindspring.com> schrieb


不需要发布三次。有时可能需要花费很多时间来获得答案。我建议至少等一天再转发。


(关注我,我在阅读WeakReference后立即跳过你的帖子

因为我从来没有处理过它。现在我会尝试...)
"Dean Slindee" <sl*****@mindspring.com> schrieb

It''s not required to post three times. Sometimes it might take many hours to
get an answer. I''d suggest to wait at least one day before reposting.

(Concerning me, I skipped your posts as soon as I read "WeakReference"
because I''ve never dealt with it. Now I''ll try...)
我的项目有一个主要形式(frmMain,
项目)和其他几个孩子在frmMain上的
大面板中绘制的表单。

在每个表单的Form_Load事件中,该表单的弱引用被加载到全局哈希表中,像这样:

Dim wr As WeakReference = New WeakReference(Me,False)

如果不是hashTable.Contains(cfrmMain)那么

hashTable。添加(cfrmMain,wr)

结束如果

我在frmMain中也有以下声明,就在
设计器代码之后,对于每个child而言。在frmMain的
面板内绘制的形式:

朋友frmAdmin作为新的frmAdmin

朋友frm任命为新的frmAppointment

朋友frmBilling作为新的frmBilling

朋友frmSystem作为新的frmSystem
每个子表单在他们的
Form_Load事件中写入frmMain上的状态栏。
问题是,子窗体的加载事件是在之前触发的,而frmMain的加载事件已经将引用放入了哈希表中。

怎么能我得到frmMain的Form_Load在孩子面前完全开火
Form_Load事件

火吗?或者,如何在
子Form_Load
事件发生之前将frmMain的条目输入hashTable?


您正在混合订单。订单是

1.创建表格

2.加载表格

3.显示表格

4.孩子画任何东西(分别改变显示)


我会适当地编码:


dim f as new frmmain

f.show''加载是在表单显示之前隐式完成

''

frmmain.refresh

frmmain。 loadchildforms''not in form_load

Loadchildforms创建子实例,所以不要声明它们As / New /

frmAdmin

另一种改进方法可能是让孩子举起活动,然后在bmM上抓住他们。在事件处理程序中,frmMain可以更新它自己的

状态栏。


除了这个特定的问题,我想找一个<

详细说明VB应用程序启动时序列发生的详细信息。
My project has a main form (frmMain, the startup object for the
project) and several other "child" forms that are painted within a
large panel on frmMain.

In each form''s Form_Load event, a Weak Reference for that form is
loaded into a global Hash table, like this:

Dim wr As WeakReference = New WeakReference(Me, False)

If Not hashTable.Contains(cfrmMain) Then

hashTable.Add(cfrmMain, wr)

End If

I also have the following declares in frmMain, just after the
designer code, for each "child" form that gets painted inside the
panel on frmMain:

Friend frmAdmin As New frmAdmin

Friend frmAppointment As New frmAppointment

Friend frmBilling As New frmBilling

Friend frmSystem As New frmSystem

Each child form writes to the status bar on frmMain in their
Form_Load event.

Problem is, the load events for the child forms are firing before

the load event for frmMain has put a reference into the hash
table.

How can I get frmMain''s Form_Load to fire completely before child
Form_Load events

fire? Or, how can I get an entry for frmMain into hashTable before
child Form_Load

events fire?
You are mixing the order. The order is
1. create form
2. load form
3. show form
4. child paints anything (resp. change the display)

I''d code it appropriately:

dim f as new frmmain
f.show ''loading is done implicitly
'' just before the form is shown
frmmain.refresh
frmmain.loadchildforms ''not in form_load
Loadchildforms creates the child instances, so don''t declare them "As /New/
frmAdmin"
Another improvement approach is probably to make the child raise events and
catch them in frmMain. In the event handler, frmMain can update it''s own
status bar.

Above and beyond this specific problem, I would like to find an
article that explains in

great detail exactly what happens in sequence when a VB application
is launched.




Sub主要是开始。它运行在

应用程序的唯一线程中。一旦所有线程终止,应用程序就会退出。如果你只需要一个线程
,那么当你的主线程结束时,应用就会结束。为了保持主要运行,必须有一个循环使线程和应用程序保持活动状态。

在Windows.Forms应用程序中,sub main包含一个消息循环

处理所有窗口消息(按键,鼠标移动,......)。如果你自己写了一个主要的子主,它可以是这样的:


sub main

application.run(new form1)

end sub


application.run包含消息循环,一旦

通过表单就会返回关闭。在这个子主页中你非常灵活,你可以用
写任何你想要的东西。


如果在项目属性中指定一个Form作为启动对象, VB

隐式为您创建(不可见)代码。它看起来像这样:


sub main

application.run(new form1)

end sub


惊喜,它与上面相同,但这段代码是固定的。在第一种情况下,

您可以根据需要随意填写Sub main。

-

Armin

如何引用及其原因:
http:/ /www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



Sub main is started. It is running in the one and only thread of the
application. The application quits as soon as all threads terminated. If you
have one thread only, the app ends when your main thread ends. To keep sub
main running, there must be a loop that keeps the thread and the app alive.
In Windows.Forms applications, sub main contains a message loop that
processes all windows messages (key presses, mouse movements,...). If you
write sub main on your own, it can look like this:

sub main
application.run(new form1)
end sub

application.run contains the message loop and it returns as soon as the
passed form has been closed. In this sub main you are very flexible, you can
write anything you want.

If you specify a Form as the startup object in the project properties, VB
implicitly creates (invisible) code for you. It looks like this:

sub main
application.run(new form1)
end sub

Surprise, it''s the same as above, but this code is fixed. In the first case,
you are free to fill Sub main as you want.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


这篇关于如何在其他依赖形式之前加载frmMain?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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