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.