473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

addhandler question

EMW
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 21 '05 #1
4 1534

Jan. 5, 2005

I am not aware of a method that removes all events that a method
handles, but you can use RemoveHandler for one specific event. You can then
implement an array of menuitems whose events are set to be handled by the
method and then call removehandler for each of the items in the array. The
format for the event handler is: RemoveHandler MnuItem.Event, Addressof
HandlerMethod
I hope this helps you!
Joseph MCAD

"EMW" wrote:
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 21 '05 #2
Why don't you use a different constructor for adding MenuItems to the
collection like below instead of adding all those event handlers.

Dim pclick As EventHandler = New EventHandler(AddressOf _ MenuItemClicked)
mnuItem.Add("Shelter", pclick)
mnuItem.Add("Building", pclick)
mnuItem.Add("BSC", pclick)

Sub MenuItemClicked()
.....
End Sub

"EMW" wrote:
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 21 '05 #3
If I have the following code, how do I remove the Delegate "pclick" where
PopMenu is my Context Menu object.

Sub MySub()
.........
Dim pclick As EventHandler = New EventHandler(AddressOf _ MenuItemClicked)
PopMenu.mnuItems.Add("Shelter", pclick)
PopMenu.mnuItems.Add("Building", pclick)
PopMenu.mnuItems.Add("BSC", pclick)
End Sub

Sub MenuItemClicked()
.....
End Sub

pclick.Remove ("What do I use for Parameters here") Thanks for any reply.
"Joseph MCAD" wrote:

Jan. 5, 2005

I am not aware of a method that removes all events that a method
handles, but you can use RemoveHandler for one specific event. You can then
implement an array of menuitems whose events are set to be handled by the
method and then call removehandler for each of the items in the array. The
format for the event handler is: RemoveHandler MnuItem.Event, Addressof
HandlerMethod
I hope this helps you!
Joseph MCAD

"EMW" wrote:
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 21 '05 #4
Sorry, the code should read: (assuming cmThs is your Context Menu Object)
..........
Dim pclick As EventHandler = New EventHandler(AddressOf _ MenuItemClicked)
cmThs.MenuItems.Add("Shelter", pclick)
cmThs.MenuItems.Add("Building", pclick)
cmThs.MenuItems.Add("BSC", pclick)
End Sub

Sub MenuItemClicked(ByVal sender As Object, ByVal e As EventArgs)
Dim m As MenuItem = CType(sender, MenuItem)
Select Case m.Text
Case "Shelter"
Case "Bulding"
Case "BSC"
End Select
.....
End Sub

"EMW" wrote:
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: EMW | last post by:
I use the following code in the POPUP event of a contextmenu: mnuItem = New MenuItem mnuItem.Text = "Shelter" cmThs.MenuItems.Add(mnuItem) AddHandler mnuItem.Click, AddressOf MenuItemClicked...
3
by: Jeffrey A. Voigt | last post by:
Can someone take a quick glace at my code and tell me why my AutoPostBackHandler function does not get fired off at all? What I'm trying to do is get all of the Buttons and DropDownList controls...
4
by: DJ | last post by:
Good morning, Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances...
2
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed...
1
by: EMW | last post by:
I use the following code in the POPUP event of a contextmenu: mnuItem = New MenuItem mnuItem.Text = "Shelter" cmThs.MenuItems.Add(mnuItem) AddHandler mnuItem.Click, AddressOf MenuItemClicked...
3
by: hartley_aaron | last post by:
Hi, I was trying to store the address of the my current handler for a particular event so as to simplify using AddHandler and RemoveHandler throughout my code. However, I cannot seem to get any...
12
by: Tom | last post by:
I use dynamically created controls all the time. I.E. I create the control in code then use AddHandler to add the necessary delegates for processing (like Click, etc). Does one have to call...
15
by: Nathan Sokalski | last post by:
I have a section of my code that dynamically creates LinkButtons to allow the user to go to the page containing a question they have not answered. The code that creates the LinkButton is called, as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.