is it possible to define the order in which winform user controls load?

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I have one control that absolutely must load before any other controls,
due to some initialisation code within it. Is there a way of getting
this control to load first? Moving the code from the load event to the
constructor isn't an option to get around this issue.

Any suggestions would be very gratefully received!!!

Greg.
 
The only option I see for now would be tweaking the designer code. My
personal preference would be still to move this portion of code elsewhere
(page_load ?).

Some more details about why this is needed may help someone to make better
suggestions.
 
Thanks Patrice.

I tried tweaking the designer code - the order in which the controls
are loaded is not reflected to the order that they are being
instantiated by my main form. So it would appear that the order in
which they are loaded is determined by something else.

I dont want to move the initialisation code into the constructor as
that is called at design time as well as design time. designmode always
returns false within the constructor and so can't be used to
differentiate between design time and run time - and I need to avoid
trying to create objects (part of my initialisation) at design time!

Thansk again.

Greg.
 
If this order (controls would be "created" in a given order but not "loaded"
in the same order ? how do you have checked this ?) is not under you control
it looks like you are out of luck.

You may still want to give some more details as it looks really an unusual
requirement. My personal strategy would be rather to get rid of this
requirement rather than trying to satisfy it.

Also if it must do something special on other controls, it could be just
implemented in a form you could inherit from.
 
I have one control that absolutely must load before any other controls,
due to some initialisation code within it. Is there a way of getting
this control to load first? Moving the code from the load event to the
constructor isn't an option to get around this issue.

You don't have any control over this.

If you absolutely require yours to load first then it is a bad design.

It sounds as if you are trying to perform some operations on the other
controls in the forms. If this is the case, I would suggest hooking your
own controls 'ParentChanged' event. When the event is fired, then you can
iterate thru the parent's control collection. You could also at that time
hook the parent's ControlAdded and ControlRemoved events in order to catch
controls that are added after your control. I haven't actually tried this
but I think it should work.

-mdb
 
You could instantiate the controls dynamically after
IntializeComponent; This would give you control in what order the
controls are loaded.
 
Back
Top