By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

AddHandler question.

P: n/a
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 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Eric,

MenuItem is a part of the MenuItemCollection, in my opinion it should be
therefore very easy to do with a (see this as pseudo not tested and typed
here) to do what I thought that you where asking.

for each MnIt as MenuItem in cmThs.MenuItems
RemoveHandler MnIt.Click, AddressOf MenuItemClicked
next

I hope that this helps?

Cor

"EMW" <so*****@MikroZoft.com>
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 22 '05 #2

P: n/a
EMW
Hi Cor,

I also managed to solve this.
I used an array of menuitems to store each created menuitem and then in the
MenuItemClicked routine I called RemoveHandler on each arrayItem.

rg.
Eric
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:OI**************@TK2MSFTNGP12.phx.gbl...
Eric,

MenuItem is a part of the MenuItemCollection, in my opinion it should be
therefore very easy to do with a (see this as pseudo not tested and typed
here) to do what I thought that you where asking.

for each MnIt as MenuItem in cmThs.MenuItems
RemoveHandler MnIt.Click, AddressOf MenuItemClicked
next

I hope that this helps?

Cor

"EMW" <so*****@MikroZoft.com>
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 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.