This is a multi-part message in MIME format.
------=_NextPart_000_000B_01C7CFCC.69E14F00
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Hi there,
Does anyone know how to (generically) determine the currently active =
form for an application using a "static" function (so I can call it from =
anywhere). There is no offiical way I've been able to find so I've =
written the following for starters:
public static Form GetActiveForm()
{
// Returns null for an MDI app
Form activeForm =3D Form.ActiveForm;
if (activeForm =3D=3D null)
{
FormCollection openForms =3D Application.OpenForms;
for (int i=3D 0; i < openForms.Count && activeForm =3D=3D null; =
++i)
{
Form openForm =3D openForms[i];
if (openForm.IsMdiContainer)
{
activeForm =3D openForm.ActiveMdiChild;
}
}
}
return activeForm;
}
However, if no MDI child forms are open when this is called then the MDI =
parent should be returned. What if there's more than one MDI parent in =
the application however (unlikely but possible I assume). How do you =
then determine which is active. In any case, the code above seems like =
a "hack" to me and I'm concerned about any issues I may be neglecting. =
In fact, the entire situation seems like a major oversight on MSFT's =
part so I'm uneasy about doing this. If someone can therefore set me on =
the right track I'd appreciate it. Thanks in advance.
------=_NextPart_000_000B_01C7CFCC.69E14F00
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.6000.16481" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi there,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Does anyone know how to (generically) =
determine the=20
currently active form for an application using a "static" function (so I =
can=20
call it from anywhere). There is no offiical way I've been able to find =
so I've=20
written the following for starters:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier size=3D2>public static Form=20
GetActiveForm()<BR>{</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2> // Returns =
null for an=20
MDI app<BR> Form activeForm =3D=20
Form.ActiveForm;<BR> if (activeForm =3D=3D=20
null)<BR> {<BR> =20
FormCollection openForms =3D =
Application.OpenForms;<BR> =20
for (int i=3D 0; i < openForms.Count && =
activeForm=20
=3D=3D null; ++i)<BR> =
{<BR> =20
Form openForm =3D=20
openForms[i];<BR> =
if=20
(openForm.IsMdiContainer)<BR> =20
{<BR> =
=20
activeForm =3D =
openForm.ActiveMdiChild;<BR> =20
}<BR> =
=20
}<BR> }</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2></FONT> </DIV>
<DIV><FONT face=3DCourier size=3D2> return=20
activeForm;<BR>}</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>However, if no MDI child forms are open =
when this=20
is called then the MDI parent should be returned. What if there's more =
than one=20
MDI parent in the application however (unlikely but possible I assume). =
How do=20
you then determine which is active. In any case, the code above =
seems like=20
a "hack" to me and I'm concerned about any issues I may be neglecting. =
In fact,=20
the entire situation seems like a major oversight on MSFT's =
part so=20
I'm uneasy about doing this. If someone can therefore set me on the =
right track=20
I'd appreciate it. Thanks in advance.</FONT></DIV></BODY></HTML>
------=_NextPart_000_000B_01C7CFCC.69E14F00--