|
-
Dec 10th, 2013, 03:14 PM
#1
[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)?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Dec 10th, 2013, 03:24 PM
#2
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>).
Last edited by dday9; Dec 10th, 2013 at 03:28 PM.
-
Dec 10th, 2013, 03:50 PM
#3
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 10th, 2013, 04:11 PM
#4
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).
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Dec 10th, 2013, 04:18 PM
#5
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 11th, 2013, 12:25 AM
#6
Re: AddHandler from a module, is that the correct way?
 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!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|