Remove Handler at Runtime

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Remove Handler at Runtime

 
0
  #1
Sep 22nd, 2009
I want to after clicking on button2,after that if i click on button1 then msg is not displayed

  1.  
  2.  
  3. Public Class Form1
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6. MsgBox("sonia")
  7. End Sub
  8.  
  9. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  10. RemoveHandler Button2.Click, AddressOf MYEVENTHandler
  11. End Sub
  12.  
  13. Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
  14.  
  15. End Sub
  16. End Class
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 25
Reputation: CodeDoctor is an unknown quantity at this point 
Solved Threads: 6
CodeDoctor's Avatar
CodeDoctor CodeDoctor is offline Offline
Light Poster

Re: Remove Handler at Runtime

 
0
  #2
Sep 22nd, 2009
Originally Posted by sonia sardana View Post
I want to after clicking on button2,after that if i click on button1 then msg is not displayed

  1.  
  2.  
  3. Public Class Form1
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6. MsgBox("sonia")
  7. End Sub
  8.  
  9. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  10. RemoveHandler Button2.Click, AddressOf MYEVENTHandler
  11. End Sub
  12.  
  13. Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
  14.  
  15. End Sub
  16. End Class

In your Form Load, setup the event handler for Button1. So, remove the statement Handles 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.
Last edited by CodeDoctor; Sep 22nd, 2009 at 9:27 pm. Reason: typo
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC