Ok, a "sort of delegate model" I'll buy.
So, now you're giving an example of what I called "Event based interaction between objects." What you are actually doing here is what Microsoft calls exposing events of constituent controls to users of your control. You give a simple example. Let's give you a little more involved one, that should be a little more useful to you.
Assume this code is in a UserControl called (tip of the hat to
strongm) HappyFish, with two text boxes, Text1 and Text2. You want to expose the KeyPress events of the two textboxes as separate events. So, you declare the events, and raise them from the keypress events inside the control. By doing this, you pass the events from inside the control to whatever is containing the control (typically a form).
Code:
Public Event T1_KeyPress(KeyAscii as Integer)
Public Event ImSoCute(ReallyIAm as Integer)
Private Sub Text1_KeyPress(KeyAscii as Integer)
RaiseEvent T1_KeyPress KeyAscii
End Sub
Private Sub Text2_KeyPress(KeyAscii as Integer)
RaiseEvent ImSoCute KeyAscii
End Sub
Now, you use the control on a form (let's say you name it HappyFish1), and want to interact with the keypress events of the two text boxes. The event handlers in your form would look like this:
Code:
Sub HappyFish1_T1_KeyPress(KeyAscii as Integer)
'do whatever, for example prevent anything but 0-9
End Sub
Sub HappyFish1_ImSoCute(ReallyIAm as Integer)
'do whatever
End Sub
I used an offbeat name in the Text2 example to illustrate that the name can be anything you want. It doesn't have to relate in any way to the name of the event it's exposing. However, it's a good idea to relate them, so that users of your control will intuitively understand which constituent control your event is addressing.
HTH
Bob