Home All Groups Group Topic Archive Search About

Need some info about the Load event of Forms and Usercontrols

Author
5 Dec 2006 6:30 PM
Franky
Threre is a Form containing a usercontrol

In the form's Load event it references a usercontrol property, say, zz

The first showdialog(formx) causes
1 usercontrol_load event
2 form_load event which causes zz as expected

the second showdialog(formx) causes
1 form_load event which causes zz as expected
2 usercontrol_load event


Note in the second situation zz ran before the Load which initializes
things.

I would like the usercontrol load event to run before any properties or
methods are executed. Is that possible to setup.



What are the sequences that form and usercontrol loads are run?

Do they always both run for each DialogShow?


What happens after the DialogShow exits? Something is left in memory, but
what? The Usercontrol? The Form? Parts of each?

The usercontrol contains a TreeView, is any of the treeview data preserved?



Thanks for any answers

Author
5 Dec 2006 11:51 PM
Charlie Brown
Franky,
When showing a form using the ShowDialog() method, your application
will create the form and display it to the screen.  When you call the
Close() method, the form will hide itself keeping everything on the
form in memory.  If you use the Form.Show() method instead it will
offer the form up for garbage collection when the Close() method is
called.

When it comes to loading things and intializing the order can change
depending on where you call the New() method of your child control.  I
like to do a lot of my initializing in the constructor call of the form
to avoid any confusion, so long as it isn't time intensive or error
prone.  I would call everything in your form's New() and see if it
works for you.


Franky wrote:
Show quoteHide quote
> Threre is a Form containing a usercontrol
>
> In the form's Load event it references a usercontrol property, say, zz
>
> The first showdialog(formx) causes
> 1 usercontrol_load event
> 2 form_load event which causes zz as expected
>
> the second showdialog(formx) causes
> 1 form_load event which causes zz as expected
> 2 usercontrol_load event
>
>
> Note in the second situation zz ran before the Load which initializes
> things.
>
> I would like the usercontrol load event to run before any properties or
> methods are executed. Is that possible to setup.
>
>
>
> What are the sequences that form and usercontrol loads are run?
>
> Do they always both run for each DialogShow?
>
>
> What happens after the DialogShow exits? Something is left in memory, but
> what? The Usercontrol? The Form? Parts of each?
>
> The usercontrol contains a TreeView, is any of the treeview data preserved?
>
>
>
> Thanks for any answers
Author
6 Dec 2006 3:38 PM
Franky
"Charlie Brown" <cbr***@duclaw.com> wrote in message
news:1165362677.454063.65140@j44g2000cwa.googlegroups.com...
> Franky,
> When showing a form using the ShowDialog() method, your application
> will create the form and display it to the screen.  When you call the
> Close() method, the form will hide itself keeping everything on the
> form in memory.

The forms Load event is called at least the first two times I do a show
dialog. Is that what you'd expect, seeing the form is already in memory?
Does it get called for each ShowDialog?

What's bothering me is that the second time, the load on the usercontrol is
run after the form load. And the form load calls a usercontrol method.

Bottom line, Second ShowDialog, the form load called a UC method before the
UC's Load event was run which reinitialized things.

If the UC is still in memory I'd be OK if it's Load was not called a second
time.

I could put a flag in the UC to indicated that it's been called before and
exit if true.

Is there a neater way, If ME.something Then Exit Sub 'This UC has already
been loaded?



Thanks a lot




>If you use the Form.Show() method instead it will
> offer the form up for garbage collection when the Close() method is
> called.
>
> When it comes to loading things and intializing the order can change
> depending on where you call the New() method of your child control.  I
> like to do a lot of my initializing in the constructor call of the form
> to avoid any confusion, so long as it isn't time intensive or error
> prone.  I would call everything in your form's New() and see if it
> works for you.


I'll check this - I don't remember where I do the New


Thanks

Show quoteHide quote
>
>
> Franky wrote:
>> Threre is a Form containing a usercontrol
>>
>> In the form's Load event it references a usercontrol property, say, zz
>>
>> The first showdialog(formx) causes
>> 1 usercontrol_load event
>> 2 form_load event which causes zz as expected
>>
>> the second showdialog(formx) causes
>> 1 form_load event which causes zz as expected
>> 2 usercontrol_load event
>>
>>
>> Note in the second situation zz ran before the Load which initializes
>> things.
>>
>> I would like the usercontrol load event to run before any properties or
>> methods are executed. Is that possible to setup.
>>
>>
>>
>> What are the sequences that form and usercontrol loads are run?
>>
>> Do they always both run for each DialogShow?
>>
>>
>> What happens after the DialogShow exits? Something is left in memory, but
>> what? The Usercontrol? The Form? Parts of each?
>>
>> The usercontrol contains a TreeView, is any of the treeview data
>> preserved?
>>
>>
>>
>> Thanks for any answers
>