469,358 Members | 1,628 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

How to tell parent window when a child window is clilcked on?

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
Aug 24 '06 #1
4 3326

Richard Lewis Haggard wrote:
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
Can't you just have the parent form listen to the child form's Click
event?

If you need more specific behaviour, you could write a new event into
the child form and have the parent form subscribe to that event.

Aug 24 '06 #2
Thank you, but restating the question does not actually provide any useful
information that will help solve the problem. I need to know how to set up
things so that a child window can notify its parent of an event in a child.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>
Richard Lewis Haggard wrote:
>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

Can't you just have the parent form listen to the child form's Click
event?

If you need more specific behaviour, you could write a new event into
the child form and have the parent form subscribe to that event.

Aug 27 '06 #3

Richard Lewis Haggard wrote:
Thank you, but restating the question does not actually provide any useful
information that will help solve the problem. I need to know how to set up
things so that a child window can notify its parent of an event in a child.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...

Richard Lewis Haggard wrote:
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
Can't you just have the parent form listen to the child form's Click
event?

If you need more specific behaviour, you could write a new event into
the child form and have the parent form subscribe to that event.
What part of "...have the parent form subscribe to that event" was
unclear?

If you are looking for code, this is what I meant:

public class ParentForm : Form
{
...
ChildForm child = new ChildForm();
child.Click += new System.EventHandler(child_Click);
child.Show();
...

private void child_Click(object sender, System.EventArgs e)
{
MessageBox.Show("The child was clicked!");
}
}

Of course, this event will occur only when the user clicks on the child
form itself and not on any of the controls contained within the form.
(Clicks on controls within the child form will, of course, be handled
by those controls and will not be seen as a Click on the form.)

If this isn't what you want, then perhaps the problem is in how you
stated your question. "Click on the child form" could mean precisely
that: a click event on the child form, in which case the above code is
what you need. Or, perhaps you meant "when the user gives the child
form focus" in which case the GotFocus event might be more appropriate.

It may also make a difference whether you are programming WinForms
(which is what I do) or WebForms (I can't speak to the subtleties of
Web programming).

As well, what you mean by "when the user clicks on the child form" may
be when the user clicks *anywhere* within the bounds of child form,
even on a control, which is a whole other kettle of fish.

The problem, from my side of the Web, is that your question is rather
vague. The child form doesn't "notify the parent of an event in the
child". The parent, rather, subscribes to one of the child's events,
and so registers its interest in something that may happen within the
child form. Are you having trouble in the parent, subscribing to
events? Or do none of the standard events for a Form meet your needs?
Or perhaps you're subscribing but your handler is never called? Or
perhaps you're using the word "event" in a general (English) sense
rather than in the technical sense of a C# event?

Rather than tossing back ironic comments, perhaps providing more
information about exactly what it is you're trying to do would get you
a better answer.

Aug 27 '06 #4
Ah! Now I understand what you meant. I knew that there must some easy way of
doing it but couldn't figure out the right keys to push in order to
accomplish the desired result. Thanks!
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
Richard Lewis Haggard wrote:
>Thank you, but restating the question does not actually provide any
useful
information that will help solve the problem. I need to know how to set
up
things so that a child window can notify its parent of an event in a
child.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@m79g2000cwm.googleg roups.com...
>
Richard Lewis Haggard wrote:
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

Can't you just have the parent form listen to the child form's Click
event?

If you need more specific behaviour, you could write a new event into
the child form and have the parent form subscribe to that event.

What part of "...have the parent form subscribe to that event" was
unclear?

If you are looking for code, this is what I meant:

public class ParentForm : Form
{
...
ChildForm child = new ChildForm();
child.Click += new System.EventHandler(child_Click);
child.Show();
...

private void child_Click(object sender, System.EventArgs e)
{
MessageBox.Show("The child was clicked!");
}
}

Of course, this event will occur only when the user clicks on the child
form itself and not on any of the controls contained within the form.
(Clicks on controls within the child form will, of course, be handled
by those controls and will not be seen as a Click on the form.)

If this isn't what you want, then perhaps the problem is in how you
stated your question. "Click on the child form" could mean precisely
that: a click event on the child form, in which case the above code is
what you need. Or, perhaps you meant "when the user gives the child
form focus" in which case the GotFocus event might be more appropriate.

It may also make a difference whether you are programming WinForms
(which is what I do) or WebForms (I can't speak to the subtleties of
Web programming).

As well, what you mean by "when the user clicks on the child form" may
be when the user clicks *anywhere* within the bounds of child form,
even on a control, which is a whole other kettle of fish.

The problem, from my side of the Web, is that your question is rather
vague. The child form doesn't "notify the parent of an event in the
child". The parent, rather, subscribes to one of the child's events,
and so registers its interest in something that may happen within the
child form. Are you having trouble in the parent, subscribing to
events? Or do none of the standard events for a Form meet your needs?
Or perhaps you're subscribing but your handler is never called? Or
perhaps you're using the word "event" in a general (English) sense
rather than in the technical sense of a C# event?

Rather than tossing back ironic comments, perhaps providing more
information about exactly what it is you're trying to do would get you
a better answer.

Sep 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by epaetz | last post: by
reply views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.