469,926 Members | 2,490 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Need some info about the Load event of Forms and Usercontrols

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

Dec 5 '06 #1
2 2749
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:
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
Dec 5 '06 #2

"Charlie Brown" <cb****@duclaw.comwrote in message
news:11*********************@j44g2000cwa.googlegro ups.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
>

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

Dec 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Marcel Balcarek | last post: by
2 posts views Thread by Lau Lei Cheong | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.