Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an event handler in VB.NET [duplicate]

Possible Duplicate:
VB.NET RemoveHandler & Anonymous Methods

If I add an event handler like this:

AddHandler s.Click, AddressOf Panel1_Click

How can I can then remove the event handler?

Private Sub Panel1_click(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Remove code
End Sub
like image 246
AoTw Avatar asked Jun 20 '12 18:06

AoTw


People also ask

How do I delete an event handler?

Go to the objects tab, view the Document object (don't click on edit) and scroll down to Event Handlers. Select the one to delete and press delete.

Can you have multiple event handlers?

Only one event handler can be assigned for every event in an element. If needed the handler can be replaced by assigning another function to the same property. Below we show how to set a simple greet() function for the click event using the onclick property.

What is an event how event handler is added?

In programming, an event handler is a callback routine that operates asynchronously once an event takes place. It dictates the action that follows the event. The programmer writes a code for this action to take place. An event is an action that takes place when a user interacts with a program.

How do you create event handlers with visual studio net?

From the Class Name drop-down list at the top of the Code Editor, select the object that you want to create an event handler for. From the Method Name drop-down list at the top of the Code Editor, select the event. Visual Studio creates the event handler and moves the insertion point to the newly created event handler.


1 Answers

You can do so using the RemoveHandler operator, as such:

Private Sub Panel1_click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim panel As Panel = CType(sender, Panel)
    RemoveHandler panel.Click, AddressOf Panel1_Click
End Sub
like image 81
Steven Doggart Avatar answered Oct 19 '22 17:10

Steven Doggart