How can a parent form tell if it has a child form?

G

Guest

Hello all,

We have a main form. We have the message loop programmed to listen for 'key
strokes' from a bar code scanner.
But when the message loop 'hears' the keystrokes, we need to know if the
main form has a child window (specifically a modal child window).

Any ideas how we ask a form if it has any child windows? We've looked into
TopMost and TopLevel, but neither of those are what we are looking for.

Thanks in advance for your reply.
 
J

Jesse Houwing

* Allan Michaels wrote, On 21-5-2007 21:05:
Hello all,

We have a main form. We have the message loop programmed to listen for 'key
strokes' from a bar code scanner.
But when the message loop 'hears' the keystrokes, we need to know if the
main form has a child window (specifically a modal child window).

Any ideas how we ask a form if it has any child windows? We've looked into
TopMost and TopLevel, but neither of those are what we are looking for.

Thanks in advance for your reply.

The best way to do this is to set a flag when a modal window is opened
and reset it when it closes from within the main form itself.

So something like:

bool showingModal = true;
using (ModalWindow mw = new ModalWindow())
{
mw.Closed += this.ResetModel;
ModalWindow.ShowDialog(this))
// get stuff if needed
}

Jesse
 
G

Guest

Thanks for the idea. However, due to the nature of the program that won't
work.
The main form has 10 tab pages, each one could bring up many different
windows. That doesn't include all the menu items that bring up windows.

Any other ideas? Thanks again for your reply.
 
L

Linda Liu [MSFT]

Hi Allan,

I suggest that you set up an owner relationship between the main form and
other 'child' forms. You could get all the owned forms through the
OwnedForms collection of the main form.

The following is a sample.
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show(this);
Form3 frm3 = new Form3();
frm3.ShowDialog(this);
}

public void GetOwnedForms()
{
for (int i = 0; i < this.OwnedForms.Length; i++)
{
Console.WriteLine(this.OwnedForms.Name);
}
}
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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