Groups | Blog | Home
all groups > vb.net > august 2005 >

vb.net : Events


Nikolay Petrov
8/22/2005 11:38:49 PM
Let's say I have a class, which raises events:

Class eventRaiser
Public Event Event1()
Private WithEvents timer1 As System.Timers.Timer
Public Sub New()
With timer1
.Interval = 2000
.Enabled = True
End With
End Sub
Private Sub timer1_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles timer1.Elapsed
RaiseEvent Event1()
End Sub
End Class


Then In my app I declare variable with of type this class and then add
handler for the event. This work's fine.
I need a way to handle events from a collection of my class. Like if I
add many instances of my class in ArrayList or similiar.
How to handle the events raised from different classes in the
colletion?
Also the IDE doesn't allow me to declare a variable with "WithEvents"
in a procedure, only on class level.
Nikolay Petrov
8/23/2005 12:04:51 AM
Ok, Cor I know this. But how to add handler for an item, which raised
events, if this item is in collection, like ArrayList or similiar?
Nikolay Petrov
8/23/2005 1:05:18 AM
No offence, but I don't see what you don't understand Cor.
I've found what I was looking for.
Thanks however.
Cor Ligthert [MVP]
8/23/2005 8:50:09 AM
Nikolay,

I don't know if I understand your question well, However you need definitly
the addhandler (and removehandler).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmaddhandlerstatement.asp

I hope this helps,

Cor

Cor Ligthert [MVP]
8/23/2005 9:38:16 AM
Nikolay,

How can an item raise an event and why would it do that.

An item an be the reason for a call of a method

If Item = "Nicolay" then help("I don't undrstand what he means")

Therefore give some sample code?

Cor

AddThis Social Bookmark Button