Menu Item Problems

Newbie here. I’m building a simple program to get more experience with Xojo Desktop. I’m having a horrible time working with the Menu items. I read the Getting Started pages about menu items - having the videos in Spanish and NO subtitles did not help at all.

Problem: I have a “File” menu item with a sub menu “Quit” - they were supplied by the Menu Editor, I suppose. Well, when I run the program, I can click on File, but it does not show the Quit item under it. I’ve added a Menu Handler for FileQuit and put a msgbox in there but it never pops up. Both are enabled and set to visible, as defaults.

What am I doing wrong? What has to be done for my sub-menu items to show up AND to fire their handler code?

Are you on Mac? If so, the Quit will show up under the File menu in the designer, but will be put under the Application’s name menu when running.

Yep - you are right - I’m on a Mac. My Msgbox fired when I clicked the Quit thingy under the name menu.

However, I added another menu item next to the File menu, created a Menu Handler for it that included a Msgbox and it doesn’t do anything. I click on “Range”, it flashes, but no message box. Arrggghhhh!

Screen Shot 2020-09-13 at 2.43.51 PM

Hi Jim,

Menus themselves don’t get events. It’s the menu items that do. It looks like your RangeMenu is a menu but has no menu items. Add a menu item to it then select Window1 and choose Insert > Menu Handler. In the Inspector, choose that menu item and add your code.

This page of the documentation will provide you with more info on handling menus. https://docs.xojo.com/UserGuide:Desktop_Menus

Hi Geoff,

Many thanks to you (and to Bill Gookin) - Got it going now. Didn’t realize that I had to build a sub-menu for my “stuff” to work. I did that, and by golly, it works!

Another question…

Now that I’ve got the Menu Item and the Handler working together, I’d like to put something in the Handler to let the user select from one of three items. I know I could place a popup box on the window itself, but it would be nice to not clutter up the window with something that will be used only once, at startup, when the user selects a “range”. Isn’t there a way to have some sort of selection scheme right in the menu handler itself?

Got it!!! I just added three sub-menu items and set a variable in the handler for each. Works great.

3 Likes

Submenu items can also act with me.index to set the variable.

First of all, you have a MenuBar with Menus.

Then, you will have MenuItem(s) in a Menu.

You may have one or more Sub-MenuItems in a Menu: and these will have more than one MenuItem (in a Sub-MenuItem).

For your next question: look at other application(s) provided with the OS on how things are done: this will greatly help you.

At last, read Human Interface Guidelines.
The link is for Apple OS, there are the same kind of documents for Linux and Windows.

Either search for that in the Internet or in this Forum to get it for the two other platforms.