Hi thomson,
Actually, you don't want to write an event handler in the User Control. You
want to raise an event in the User Control, which can be handled by an event
handler in the form hosting it, if I understand you correctly. To make sure
that I DO understand you correctly, let me restate your problem, and let me
know if my interpretation is correct.
You have a User Control, which is similar to a Page in that it is a Control
that hosts other Controls. You mention that these hosted Controls, 4
buttons, fire events which are handled by the User Control hosting them. So
far, so good. Right? Okay, now don't forget that I mentioned that the Page
which hosts the User Control is similar in this respect to the User Control
itself, in that any Control can host other Controls that raise events, and
subscribe to the events with event handler methods.
So, what you want to do is to have the User Control, like a Button Control,
RAISE an event when it finishes a process of some kind, that the Page which
hosts that Control can respond to with its own event HANDLER method.
Did I get the problem right? I think it would help for you to fully
understand the following terms:
EventArgs - A class from which EventArgs classes are derived via
inheritance. EventArgs classes may or may not contain data (information)
about the class which raised the Event, or about the process in which the
Event was raised.
Delegate - A "template" for an Event Handler method, specifically for a
certain EventArgs type (class). A Delegate is similar to a "stubbed-out"
method, that is, a method that contains no process, but only a signature
(return type, name and parameters).
Raising an Event - a process that creates an EventArgs class, or a class
that inherits EventArgs, and broadcasts it to any subscribers to the Event.
Note that the broadcast itself is synchronous, that is, happening in a
sequence of instructions (process), but that the Event Handler method is
asynchronous, that is, happening in a separate thread from the current
execution thread in the class that responds to the Event.
Event Handler - a special method that has a signature matching a delegate
method for a specific type of EventArgs class. The Event Handler operates
asynchronously (in a spearate thread) from the current process being
executed by that class (the class that subscribes to the Event).
Subscribing to an Event - a process which "wires up" an EventHandler method
to an Event which may or may not be raised by another class.
Now, as to how to write the code, well, it differs in C# and VB.Net
(surprise, surprise). So, if you can tell me which language you're using, I
can give you some examples. If you're using VB.Net, this may account for
some of the confusion, as VB.Net can hide a lot of this, and allows you to
write simpler-LOOKING code to raise and handle events. Under the hood, of
course, both languages are doing the same thing, but it is actually easier
to see what is going on in C#, which is more strict about the code you
write.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.