943,822 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1620
  • VB.NET RSS
Sep 22nd, 2009
0

Remove Handler at Runtime

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

VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Sep 22nd, 2009
0

Re: Remove Handler at Runtime

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

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 6
Light Poster
CodeDoctor is offline Offline
25 posts
since Sep 2009
Nov 19th, 2011
0
Re: Remove Handler at Runtime
you can use RemoveHandler statement for doing this

check this code:
http://www.authorcode.com/add-and-re...r-dynamically/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hscoder is offline Offline
5 posts
since Sep 2011
Message:
Previous Thread in VB.NET Forum Timeline: Populate Combobox depending on other combobox
Next Thread in VB.NET Forum Timeline: Using a button in runtime





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC