Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, January 17, 2013 10:35 PM
How do I set up an event listener in VB.NET?
Basically I have a flash player (in VB.NET) which plays a clip but I can't detect when it ends but I assume there is an event which occurs when the clip ends. What I'd like to know is, how do I set up an event listener to inform me what events have just occurred? (so I know what event to use as a trigger)
All replies (6)
Friday, January 18, 2013 4:54 AM ✅Answered
here is an example of what John and Cor are talking about, plus a little extra information.
Option Strict On
Public Class Form1
'Since you did not declare this button with "Friend WithEvents", you have
'To use "AddHandler" to handle events
Dim Button1 As New Button With {.Parent = Me}
'But If you declare using friends withevents,
'you can take advantage of the handles clause
Friend WithEvents Button2 As New Button With {.Parent = Me}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Controls.Add(Button1)
Me.Controls.Add(Button2)
Button1.Left = 0
Button2.Left = Button1.Width
AddHandler Button1.Click, AddressOf Button1_Click
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("Boo! you clicked button1!")
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
MsgBox("Boo! you clicked button2!")
End Sub
End Class
“If you want something you've never had, you need to do something you've never done.”
Don't forget to mark helpful posts and answers ! Answer an interesting question? Write a new article about it! My Articles |
*This post does not reflect the opinion of Microsoft, or its employees.
Thursday, January 17, 2013 11:04 PM
You use the AddHandler statement to set up an event listener in VB.NET. Find the events available using intellisense or the Object Browser.
Thursday, January 17, 2013 11:14 PM
You use the AddHandler statement to set up an event listener in VB.NET. Find the events available using intellisense or the Object Browser.
How exactly do I do this? not being annoying just never done this before
Thursday, January 17, 2013 11:32 PM
What specifically don't you understand in the example for the AddHandler statement in the help files?
Thursday, January 17, 2013 11:34 PM
Like John wrote, you don't listen. You handle the thrown events.
If there cannot be an event thrown by a class, you also can not handle them.
So look at which events your flash player throws, and handle them.
That can be for every class different.
Success
Cor
Friday, January 18, 2013 1:56 PM
Here is a user defined event.
Public Event foobar(p1 As Integer, p2 As String)
'AddHandler foobar, AddressOf handle_foobar
Private Sub handle_foobar(p1 As Integer, p2 As String) Handles Me.foobar
Stop
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
RaiseEvent foobar(1, "one")
End Sub
"Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it." JohnWein