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 12 4202
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,
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
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...) 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 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
"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...) 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 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
Armin,
Thank you so much for your insightful reply. I spent all day reworking the
communications between the main form and it's many children, based on your
suggestions. I am pleased to say that everything is working fine now. Many
thanks for erasing some of the fuzzy areas in my thinking.
Your second suggestion of using RaiseEvents to send status messages from the
child forms to the main form's status bar is also appealing. I have not got
it working yet, but here is what I have so far:
In frmMain:
Private WithEvents frm As New frmChild
Private Sub frm_StatusMessage(ByVal strMessage As String) Handles
frm.StatusMessage
MessageBox.Show(strMessage, "RaiseEvent", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub
In frmChild:
Public Event StatusMessage(ByVal strStatus As String)
RaiseEvent StatusMessage("Houston, we have a problem")
Syntax is accepted, but the event is not trapped by frmMain. Any
suggestions?
Dean Slindee
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de... "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...)
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 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
Armin,
Thank you so much for your insightful reply. I spent all day reworking the
communications between the main form and it's many children, based on your
suggestions. I am pleased to say that everything is working fine now. Many
thanks for erasing some of the fuzzy areas in my thinking.
Your second suggestion of using RaiseEvents to send status messages from the
child forms to the main form's status bar is also appealing. I have not got
it working yet, but here is what I have so far:
In frmMain:
Private WithEvents frm As New frmChild
Private Sub frm_StatusMessage(ByVal strMessage As String) Handles
frm.StatusMessage
MessageBox.Show(strMessage, "RaiseEvent", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub
In frmChild:
Public Event StatusMessage(ByVal strStatus As String)
RaiseEvent StatusMessage("Houston, we have a problem")
Syntax is accepted, but the event is not trapped by frmMain. Any
suggestions?
Dean Slindee
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de... "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...)
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 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
Hi Dean,
I reviewed your code snippet and it seems correct for the event handling.
The following MSDN arcticle describes it in details:
Raising Events and Responding to Events http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/raiserespeven.asp
For further research, could you please tell me when you call RaiseEvent in
frmChild? Is it possible for you to post a simple reproducible project?
I look forward to hearing from you.
Have a nice day!
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.
Hi Dean,
I reviewed your code snippet and it seems correct for the event handling.
The following MSDN arcticle describes it in details:
Raising Events and Responding to Events http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/raiserespeven.asp
For further research, could you please tell me when you call RaiseEvent in
frmChild? Is it possible for you to post a simple reproducible project?
I look forward to hearing from you.
Have a nice day!
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 I have not got it working yet, but here is what I have so far: In frmMain: Private WithEvents frm As New frmChild
Private Sub frm_StatusMessage(ByVal strMessage As String) Handles frm.StatusMessage
MessageBox.Show(strMessage, "RaiseEvent", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
In frmChild:
Public Event StatusMessage(ByVal strStatus As String)
RaiseEvent StatusMessage("Houston, we have a problem")
Syntax is accepted, but the event is not trapped by frmMain. Any suggestions?
I guess you never show frm but another instance. Where is Raiseevent
located? Set a breakpoint at Raiseevent and look if it's reached.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Dean Slindee" <sl*****@mindspring.com> schrieb I have not got it working yet, but here is what I have so far: In frmMain: Private WithEvents frm As New frmChild
Private Sub frm_StatusMessage(ByVal strMessage As String) Handles frm.StatusMessage
MessageBox.Show(strMessage, "RaiseEvent", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
In frmChild:
Public Event StatusMessage(ByVal strStatus As String)
RaiseEvent StatusMessage("Houston, we have a problem")
Syntax is accepted, but the event is not trapped by frmMain. Any suggestions?
I guess you never show frm but another instance. Where is Raiseevent
located? Set a breakpoint at Raiseevent and look if it's reached.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Thanks for the link to the Microsoft web page. I built the example, which
eventually
led me to discover the solution to being able to get RaiseEvent working in
my project.
Thanks again.
Dean Slindee
"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:5h*************@cpmsftngxa06.phx.gbl... Hi Dean,
I reviewed your code snippet and it seems correct for the event handling. The following MSDN arcticle describes it in details:
Raising Events and Responding to Events http://msdn.microsoft.com/library/de...us/dndotnet/ht ml/raiserespeven.asp
For further research, could you please tell me when you call RaiseEvent in frmChild? Is it possible for you to post a simple reproducible project?
I look forward to hearing from you.
Have a nice day!
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.
Thanks for the link to the Microsoft web page. I built the example, which
eventually
led me to discover the solution to being able to get RaiseEvent working in
my project.
Thanks again.
Dean Slindee
"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:5h*************@cpmsftngxa06.phx.gbl... Hi Dean,
I reviewed your code snippet and it seems correct for the event handling. The following MSDN arcticle describes it in details:
Raising Events and Responding to Events http://msdn.microsoft.com/library/de...us/dndotnet/ht ml/raiserespeven.asp
For further research, could you please tell me when you call RaiseEvent in frmChild? Is it possible for you to post a simple reproducible project?
I look forward to hearing from you.
Have a nice day!
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: yagish |
last post by:
Hi Techies,
Am really new with the Oracle 9i Forms and am searching for a way to
perform Load Balancing in Oracle 9i Forms Application. Its not a J2EE
application, so cannot go the OC4J way.
I...
|
by: brianbender |
last post by:
I am trying to load and unload assemblies dynamically and call methods
and properties when loaded into an Appdomain
I can load assemblies all day in the current AppDomain without
references and...
|
by: Dean Slindee |
last post by:
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...
|
by: Dean Slindee |
last post by:
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...
|
by: Elmo Watson |
last post by:
Let's say I have a child form - frmEdit - on that form a RichText Box called
txtedit
So - in VB6 days - I used to be able to refer to that particular active
form's Rich Text box - like this:
...
|
by: Brett Romero |
last post by:
If my UI app uses three DLLs and two of those DLLs reference something
named utilities.dll, does the UI app load utilities.dll twice or does
the compiler recognize what is going on and load...
|
by: soahil |
last post by:
Hi and thanks to pragatiswain for reply.
i tell u about tables in the database.
TABLE NAMES are "SUB_HEAD","CATEGORY","COMPANY","BILL","BILL_DETAIL.
I've a master detail relationship b/w BILL...
|
by: jmartmem |
last post by:
Greetings,
I have an ASP page with two dynamic dependent list boxes written in JavaScript. My dependent lists work great, but my problem is that the values for "Program_Name" and "Project_Name"...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |