[RESOLVED] AddHandler from a module, is that the correct way?
I'm trying to use only the suggested ways to interfere with the controls on my forms.
Here is a specific question:
I need to AddHandles during Runtime. Actually I do that from a module like:
vb Code:
For Each g As usrGram In MainForm.GramList
AddHandler b.PingerPing, AddressOf g.Ping_zeichnen 'b as an ObjectType with a Event called PingerPing
Next
Is that the recommended way or should I try to move that code into the class of the Form (using an Event to trigger it)?
Re: AddHandler from a module, is that the correct way?
Personally the way that I would do it is the latter. The reason is because what if you decide to change your project around and you no longer have a MainForm or MainForm is a completely different form? That can be avoided by simply calling Me.<some sort of collection>.
Edit - To elaborate a bit more; if GramList is a custom class, then it may be better to create the handlers in that class as opposed to on the main form. But you'd have to weigh out if it's more beneficial to do that, which really we can't judge without seeing the class itself(assuming it even is a class, it could just be a list of <t>).
1 Attachment(s)
Re: AddHandler from a module, is that the correct way?
this is the correct way:
Code:
Public Class UserControl1
Public Event myEvent(ByVal sender As Object, ByVal e As MouseEventArgs)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent myEvent(Me, New MouseEventArgs(Windows.Forms.MouseButtons.Left, 1, 0, 0, 0))
End Sub
End Class
Attachment 108153
Re: AddHandler from a module, is that the correct way?
@ dday9 My Gramlist is a Collection of UserControls.
@.paul. The problem with the solution to add the handler in UserControl Class is that it needs the add and remove for each creation and deletion of the other Object-Type ( b in the example).
Re: AddHandler from a module, is that the correct way?
if it's an event of an object in a uc, + the handler is in the uc, you should setup the handling in the uc
if it's an event of an object not in a uc, + the handler is in the uc, your code is ok
Re: AddHandler from a module, is that the correct way?
Quote:
Originally Posted by
.paul.
if it's an event of an object not in a uc, + the handler is in the uc, your code is ok
It's this situation, sorry for not telling in the first place.
Thanks for the advice, Solved!