ContextMenus??

K

Karthik Vazhkudai

Hi All:

I have a contextmenu with each menu item comprising of a set of child
menus. This contextmenu is attached to an image control and is
displayed only when the user right-clicks on the image control. I am
having trouble in clearing out the contextmenu when the user
right-clicks and selects a menu option. What happens is that while the
contextmenu itself vanishes it leaves a small rectangular box on the
screen which only vanishes when I manually do an ALT-TAB into another
window and go back to my window with the contextmenu. The code I have
within the event handler of the menu option is as below:

'Somewhere, I attach an event handler to the menu
m.MenuItems.Add("&Event for Alarm ", New System.EventHandler(AddressOf
Me.JumpTo_OnClick))
..
..
..
'Event handler for the menu option
Protected Sub JumpTo_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
...
For Each mnuItem As MenuItem In ContextMenu1.MenuItems
mnuItem.Enabled = False
mnuItem.Visible = False
mnuItem = Nothing
Next
ImageControl.ContextMenu = Nothing
ImageControl.Invalidate()
End Sub

Any suggestions as to the best way of clearing out a context menu is
most appreciated.

--Karthik
 
O

One Handed Man [ OHM# ]

When selecting the Options of the Contextmenu. Try using the MouseUp event
not the mouseDown

OHM

Karthik said:
Hi All:

I have a contextmenu with each menu item comprising of a set of child
menus. This contextmenu is attached to an image control and is
displayed only when the user right-clicks on the image control. I am
having trouble in clearing out the contextmenu when the user
right-clicks and selects a menu option. What happens is that while the
contextmenu itself vanishes it leaves a small rectangular box on the
screen which only vanishes when I manually do an ALT-TAB into another
window and go back to my window with the contextmenu. The code I have
within the event handler of the menu option is as below:

'Somewhere, I attach an event handler to the menu
m.MenuItems.Add("&Event for Alarm ", New System.EventHandler(AddressOf
Me.JumpTo_OnClick))
.
.
.
'Event handler for the menu option
Protected Sub JumpTo_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
...
For Each mnuItem As MenuItem In ContextMenu1.MenuItems
mnuItem.Enabled = False
mnuItem.Visible = False
mnuItem = Nothing
Next
ImageControl.ContextMenu = Nothing
ImageControl.Invalidate()
End Sub

Any suggestions as to the best way of clearing out a context menu is
most appreciated.

--Karthik

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Karthik Vazhkudai) scripsit:
'Event handler for the menu option
Protected Sub JumpTo_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
...
For Each mnuItem As MenuItem In ContextMenu1.MenuItems
mnuItem.Enabled = False
mnuItem.Visible = False
mnuItem = Nothing
Next
ImageControl.ContextMenu = Nothing
ImageControl.Invalidate()
End Sub

Why don't you remove the items with
'ContextMenu1.MenuItem1.Items.Remove(...)'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top