473,729 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1602
* 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.Sho wDialog(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.Sho wDialog(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(obje ct 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.WriteLi ne(this.OwnedFo rms[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
6208
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 rarely refer to a subform ir parent form's controls or records from the other form. Instead, I call a procedure in that form that does the job. That's all fine and good, and nothing at all revolutionary, but it leaves one with an annoying...
13
7409
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 created forms for both those tables, and inserted the child table form into the master table form as a subform. It works just as it is supposed to, in that I can create a new master record, and then add detail records.
1
3368
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 on any field in the parent form it will search that field. However if I have focus set to a field in the child form it fails. What I want to do is set focus to field1 of the parent table but ONLY if focus is on a field in the child form. Is...
37
2079
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 its parent? That is, when I look at either "Parent" or "ParentForm" in Form2, they both show "Nothing".
4
3635
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 possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
2
2444
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 of the child forms. Now lets say I have a child form called "Child." When I open up that child form from "Main" I shut off the menu on "Main" so that the user cannot open up any other forms while they are in the "Child" form.
4
3564
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
2745
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 speciality XML file editor, used to create and edit a special XML file. It is an MDI app since I want users to be able to have multiple XML files open at the same time. The parent form has the usual Menu bar with a File menu that has the
4
6058
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 this is all very difficult to explain in words, please bear with me as I endevour to explain what it is I am trying to do. It would be helpful if I could attach a graphics file to this posting that would help explain what it is I'm trying to achieve...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.