954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Remove Handler at Runtime

I want to after clicking on button2,after that if i click on button1 then msg is not displayed

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("sonia")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RemoveHandler Button2.Click, AddressOf MYEVENTHandler
    End Sub

    Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
sonia sardana
Posting Whiz
326 posts since Mar 2008
Reputation Points: 0
Solved Threads: 8
 

I want to after clicking on button2,after that if i click on button1 then msg is not displayed

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("sonia")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RemoveHandler Button2.Click, AddressOf MYEVENTHandler
    End Sub

    Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class


In your Form Load, setup the event handler for Button1. So, remove the statementHandles Button1.Click at the end of the Button1.Click procedure.

In your Form_Load place the following:
Addhandler Button1.Click, AddressOf MYEVENTHandler

In your MYEVENTHandler place the following code:
msgbox ("sonia")

In the Button2_Click, use the existing code you have, it will work.

Hope this helps.

CodeDoctor
Light Poster
25 posts since Sep 2009
Reputation Points: 10
Solved Threads: 6
 

you can use RemoveHandler statement for doing this

check this code:
http://www.authorcode.com/add-and-remove-action-handler-dynamically/

hscoder
Newbie Poster
6 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Infraction Points: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You