Checking if Windows Form is open?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

Through my MDI application, I open a FormX that is opened outside of the
application (not an MDI child). How can I check if the Form's open so I
don't load two instances of the same window? Is it possible that, within the
MDI container, a Form can have TopMost equal to true? For some reason,
TopMost property only works when the window's opened outside the MDI
container.

Thanks.
 
Here's one way to accomplish the first part of your question. As to the
second part, I'll leave that to someone else because it's late :)

private FavoritesFrm _FavoritesFrm;
....
private void button1_Click(object sender, System.EventArgs e)
{
if (_FavoritesForm == null)
{
_FavoritesForm = new FavoritesFrm();
_FavoritesForm.Closed += new EventHandler(_FavoritesForm_Closed);
}
_FavoritesForm.WindowState = FormWindowState.Normal; // bring it from
the taskbar if necessary
_FavoritesForm.Show();
}

private void _FavoritesForm_Closed(object sender, EventArgs e)
{
_FavoritesForm = null;
}

HTH,
ShaneB
 
Back
Top