Remove a MenuItem from a Menu ?

In the project I try to complete its features, I wanted to remove selectively (user selected) a MenuItem (one at the time).

Of course, I have a Clear this menu entry (watch the code below), but sometimes, we just want to remove one (or more), but not all MenuItem(s).

Nota: this is what some people want to get in the IDE for its own sake.

The code below is located in a MenuItem SubClass (I need to control some Edit functions like Copy / Cut, Paste [I forgot which one), in the Action event. I removed the code previously there to get a clear example. That is the reason why I have [code]Return True[/code] just before End If.

My question is: do you think this code is correct ? (not to ask if it is 100% Rock Solid !)
It seems to be working fine AFAIK. *

[code]Function Action() As Boolean
// Declare the needed variables
Dim RecentMI As MenuItem
Dim Clear_Name As String

// Put the RecentMenu first Item
Clear_Name = “Clear this menu”

// Get a reference of the Recent Menu in the MenuBar
RecentMI = MainMenuBar.Child(“RecentMenu”)

// If the shift Key is down and the selected MenuItem is not Clear_Name
If Keyboard.AsyncShiftKey And Me.Text <> Clear_Name Then
// Remove the selected MenuItem
RecentMI.Remove(Me)

// Stop here
Return True

End If

// Many lines below have been removed…

End Function[/code]

I am amazed that I could write this code so easily, without error, without black magic…

That looks fine. I don’t know if shift-click is the right user action for this, but since there isn’t any standard for removing a menu item, you might as well use it. That said, you should use Keyboard.ShiftKey instead of the Async version.

Thank you.

Me too.

I used this by a process of elimination: I cannot use the Control Key, nor the alt key (option key !), etc. (the project runs on OS X / Windows). Shift was looking fine.

It works too *. I do not recall why I used to use the Async version.

  • I tested it and press the shift key after a click in the Menu.

PS: with time, I had to use more strange keyboard shortcuts because one OS or another started to use… MINE ! It was mine, oh boy :wink:

To insert a Tab character in a TextArea, I used (I forgot, but I think it was a two keypress) and now OS X use it. Same for Cmd-Shift-R (taken by OS X for AirDrop), but I forgot the new one and what it does (the application was compiled with RS or RB 2009r5…).

ShiftKey is the state of the key at the time the event was generated. AsyncShiftKey is the state of the key at the time the code runs. It could potentially be different.

Menu shortcuts are usually a necessity for functions that are used often.

Is it really necessary for a menu option removal ?

No, and I do not talk about that.