Unique references to MDI children

  • Thread starter Thread starter BVO
  • Start date Start date
B

BVO

I need to keep track of my MDI child forms to activate
any one of them whenever I need to.

There are two possibilities as far as I can see:

- each forms index in the MDIChildren collection
- each forms Handle property.

The first one doesnt offer my a unique reference cause
the indexes change when forms are closed. I guess I
should use the Handle but how do I activate a form based
on its Handle?

Any other way?

BVO
 
Try this (assumes that you know the Handle if the form to activate and it is
stored in a variable called handle)

foreach ( Form frm in MdiChildren ) {
if ( frm.Handle==handle ) {
frm.Activate();
break;
}
}
 
BVO,

You could always use a Hashtable to keep track of the instances. Each
MDI child should generate a unique hashcode, so you could place the MDI
children into a Hashtable. Then, instead of getting the handle, you could
just check to see if the key exists in the hash, and if it does, then
activate the form.

Hope this helps.
 
assign different name/text or something else to each of the forms (or
declare public string/int and give each form different value)
 
Back
Top