473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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.

--
Allan Michaels
Ann Arbor, MI
May 21 '07 #1
4 1584
* 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
May 21 '07 #2
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.

--
Allan Michaels
Ann Arbor, MI
"Jesse Houwing" wrote:
* 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
May 21 '07 #3
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[i].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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

May 22 '07 #4
Thank you for your help Linda. Your post answers my questions.

--
Allan Michaels
Ann Arbor, MI

May 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
1
by: tdmailbox | last post by:
Is there a vb command that can tell me if I have focus in the child or parent form? Basicly I have a search macro that needs me to have focus to any field in the parent form. If my focus is set...
37
by: Geoff Jones | last post by:
Hi Suppose I have two forms: Form1 and Form2. I create and show an instance of Form2 in the code of Form1 e.g. Dim myForm2 = New Form2 myForm2.Show() How do I tell myForm2 that Form1 is...
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
2
by: Matt | last post by:
Ok here is my problem: I have a MDI parent form called "Main" that I declare in a public module when I start up my program. This form holds the drop down menu that allows my users to access all...
4
by: Richard Lewis Haggard | last post by:
What is the mechanism by which a child window can notify its parent that it has been clicked on? -- Richard Lewis Haggard www.Haggard-And-Associates.com
3
by: zacks | last post by:
Forgive me if this has been already asked an answered, I did do a search both here and in VS2005 Help, but I can't find the answer to my question. I am developing an MDI application that is a...
4
by: Harlequin | last post by:
I have a question concerning the need to trigger events within a "child" subform which is itself enbedded within a master "parent" form and which is accessible via a tab in the parent form. Becuase...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.