Detecting active forms

J

Joza

Hi!

I have MDI and two forms, Form1 and Form2. If I open From1 and then
Form2 how to detected from Form1 that Form2 is also opened?!
Is that possible?!

Thnx.

J.
 
M

Matt

Hi!

I have MDI and two forms, Form1 and Form2. If I open From1 and then
Form2 how to detected from Form1 that Form2 is also opened?!
Is that possible?!

Thnx.

J.

Assuming that Form1 and Form2 are both children of the MDI form, the
MDIChildren property will give this to you.

Form[] charr= this.MdiChildren;

foreach (Form chform in charr)
if ( chform.name == "form1" ) // or two...
 
P

Peter Duniho

Hi!

I have MDI and two forms, Form1 and Form2. If I open From1 and then
Form2 how to detected from Form1 that Form2 is also opened?!
Is that possible?!

Well, typically if Form1 needs to know about an open instance of Form2,
that should be handled as part of your general design, such that the
reference to Form2 is explicitly passed to Form1 when it's opened.

However, if for some reason your design doesn't lend itself to treating
the forms this way, you can always get a list of all of the open forms
using the Application.OpenForms property.

Pete
 
J

Joza

Matt said:
Assuming that Form1 and Form2 are both children of the MDI form, the
MDIChildren property will give this to you.

Form[] charr= this.MdiChildren;

foreach (Form chform in charr)
if ( chform.name == "form1" ) // or two...

Thnx, but this only works if i call it from MDI, but how i said i have
two children forms, Form1 and Form2 and i want to detect if Form2 is opened
if i click on, for example, on button on Form1.
 
M

Matt

Matt said:
Assuming that Form1 and Form2 are both children of the MDI form, the
MDIChildren property will give this to you.
Form[] charr= this.MdiChildren;
foreach (Form chform in charr)
   if ( chform.name == "form1" ) // or two...

Thnx, but this only works if i call it from MDI, but how i said i have
two children forms, Form1 and Form2 and i want to detect if Form2 is opened
if i click on, for example, on button on Form1.

Take a look at the Application.OpenForms property.
 
P

Peter Duniho

it is not supported in .Net 1.1 :(

You never said you needed something that works in .NET 1.1.

Personally, I think it's time to upgrade. We're up to .NET 3.5 now. Even
..NET 2.0 had compatibility settings to deal with most (all?) of the
difference in behavior that might otherwise break an application written
for .NET 1.1 when moved to a later version. With very few exceptions,
anyone who is sticking with .NET 1.1 now is just dragging their heels.

But, if you insist, you will have to do this by tracking the open forms
yourself. Which, as you may have noted from my other reply, is what I
think is a better approach anyway in most cases. Unless what you really
want to do is enumerate all of the open forms, it's better to just make
the references between forms explicit. That way, when a specific form is
needed, you just go straight to it.

You can either pass a form reference to another as needed, or if a form
that you want to access from another form lends itself to the singleton
design pattern, you could implement it that way and access it via the
singleton class's "instance" member.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top