Load events happens at strange times

D

**Developer**

I have a Form (FV&C) containing a userconrtrol (CF&E)

I do a ShowDialog for the form and the form's Load calls a method of the
UserControl.

The first time I do this the usercontrol appears on the form as I'd expect
after the method had been run.

The second time I do this the usercontrol appears on the form as if the
usercontrols Load had last been run.

I peppered the code with writes and the following resulted.

Note that for the fist time, the usercontrol's Load runs before the form's
Load starts.

But, notice at the bottom of the list that for the second time, the
usercontrol's Load runs after the form's Load ends.

Does this make sense to you?

Any suggestions as to what is going on?

I need to have the CF&E Load run before the called method or better, if the
usercontrol remember from the last time, not to run at all.

Thanks


FV&C New Staring
CF&E New Staring
CF&E New Ending
FV&C New Ending
Call FV&C method
FV&C.ShowDialog
CF&E Load Staring
CF&E Load Ending
FV&C Load Staring
Called a method in CF&E
FV&C Load Ending
FV&C Closing
FV&C.ShowDialog Returned
Call FV&C method
FV&C.ShowDialog
FV&C Load Staring
Called a method in CF&E
FV&C Load Ending
CF&E Load Staring
CF&E Load Ending
FV&C Closing
FV&C.ShowDialog Returned
 
T

tomb

**Developer** said:
I have a Form (FV&C) containing a userconrtrol (CF&E)

I do a ShowDialog for the form and the form's Load calls a method of the
UserControl.

The first time I do this the usercontrol appears on the form as I'd expect
after the method had been run.

The second time I do this the usercontrol appears on the form as if the
usercontrols Load had last been run.

I peppered the code with writes and the following resulted.

Note that for the fist time, the usercontrol's Load runs before the form's
Load starts.

But, notice at the bottom of the list that for the second time, the
usercontrol's Load runs after the form's Load ends.

Does this make sense to you?

Any suggestions as to what is going on?

I need to have the CF&E Load run before the called method or better, if the
usercontrol remember from the last time, not to run at all.

Thanks


FV&C New Staring
CF&E New Staring
CF&E New Ending
FV&C New Ending
Call FV&C method
FV&C.ShowDialog
CF&E Load Staring
CF&E Load Ending
FV&C Load Staring
Called a method in CF&E
FV&C Load Ending
FV&C Closing
FV&C.ShowDialog Returned
Call FV&C method
FV&C.ShowDialog
FV&C Load Staring
Called a method in CF&E
FV&C Load Ending
CF&E Load Staring
CF&E Load Ending
FV&C Closing
FV&C.ShowDialog Returned
My guess is you are not using a form variable, but rather loading the
form directly. Using a form variable, you will then call New, and the
process should proceed as in the first portion.

Tom
 
D

**Developer**

Maybe the problem is because I use the same Form variable for two
ShowDialog's.
As normal with ShowDialog, the form is closed at the end of the first
ShowDialog run.
What happens the second time I do ShowDialog

I think that must be the problem.
I want to keep the form around because it contains data that I need.
So I do ShowDialog on the form
The form closes itself when finshed
I do ShowDialog later thinking ( maybe not thinking clearly) that my data
will still be there and the form will simply become visible.



In Declarations I do
Friend WithEvents mFormVolAndChaps1 As CAG.formVolAndChaps.FormVolAndChaps =
New CAG.formVolAndChaps.FormVolAndChaps



On menuitem click event I do

Console.WriteLine("Call FV&C method")

mFormVolAndChaps1.Action =
FormVolAndChaps.FormVolAndChaps.ActionType.CreateNewVolumeFolder

Console.WriteLine("FV&C.ShowDialog")

mFormVolAndChaps1.ShowDialog()

Console.WriteLine("FV&C.ShowDialog Returned")

' It's the second time I click that I have a problem.

' I've noticed that the usercontrol Visible property is True the
first time and False the second time!




Comments?

I believe the above procedure would be OK if I were using Show instead of
ShowDilog - correct?


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top