Question Multi Usercontrol / RaiseEvents

siklife

New member
Joined
Dec 21, 2009
Messages
2
Programming Experience
5-10
Here's the problem, Since .NET doesn't support control arrays..

I have a user-control in a separate library, the with the Event's on a main form on the main project, the event will raise on the form for a single control via

on the form, as you can see, handles wouldn't allow arrays, such as listOf soo only a single usercontrol can raisethe event in this thread? and since they are created on run time you can't preguess how many would ever be loaded, nor what the name types would be.. List(Of UserControl) just wouldn't work in the handles property.

VB.NET:
    Private WithEvents Bot As New BotCore.Core

    Private Sub _Connection(ByVal lColor As System.Drawing.Color, ByVal sResult As String) Handles Bot._Connection
        AddChat(rtbChat, FormatChat._Talk, lColor, sResult)
    End Sub


now in the usercontrol library
VB.NET:
    '// Connection Status Login (Optional w/color).
    Public Delegate Sub DelegateConnection(ByVal lColor As System.Drawing.Color, ByVal strResult As String)
    Public Event _Connection As DelegateConnection


this code is the only way it works, but is not code to support multi controls.. I need to figure out how i can load the control more then once and still call the same event
 
So your saying...
VB.NET:
Dim tb() As Textbox
...is not an array of textboxes?

List(Of T) would be the way to store them if you need to.

If you addhandler all these textboxes to 1 event sub, all you need is this...
VB.NET:
DirectCast(sender, Textbox)
...to find out which one triggered the event.

I have used many UCs with the same events all wired to a routed event sub and they work flawlessly.
 
Last edited:
Okay, but this is events coming from an external usercontrol library.

Now on the project that's not the library, you can use Sub blahblah Handles Library.Event..

I'll attempt looking up more depth into Direct Cast for this problem, I've tried at-least 10 different solutions last night.

EDIT: your solution looks like it'd work for an internal control or inside the user-control and has no effect or help for the events I'm trying to pass-back, I maybe wrong, if someone could school me on this, I'd like to hear about it, thanks.
 
Last edited:
Even if you wired up all your UC's to this sub, it does not look like there is an UC object to DirectCast out. It is a pointer to a custom sub (AddChat). What if all the UC's executed this method you have in the _Connection event - would it behave correctly, or would this method have to take on a parameter of this UC type?
 
Back
Top