Forum > Editor

OnMouseEnter event on MenuItem


I am a beginner in Lazarus.
I want to code an OnMouseEnter event on a MenuItem.
In this event I will create dynamicaly some sub Menu Items under this MenuItem.
But in the IDE, in the object inspector, this event does'nt exist.

In my work with menu items, I was able to bring the OnMouseEnter method to the events, but not get it to work.
After digging a little deeper, I realized that the menu options are not aware of mouse events. Because they do not respond to the CM_MOUSEENTER method used to capture mouse events.
As far as I understand it's not possible to handle menu items, possibly an api of the OS, and mouse events with current standards!!!
If there is a mistake, I would be glad if the Masters corrected it. Respects.

Why don't you do this in the OnClick event?


1. I have a program in Powersell and it is possible to code an "on mouse enter" on a menu item. So we are sure this event exists in windows.
But i want to transform my program to Lazarus because i think compiled is better than interpreted
2. I explain what i want to do. The menu item is "recently open files" and it have in subitems a list of files. But I can have several instances of my program opened at the same time so i can not know the list of recently open files before the moment i go to the menu item. On the mouse enter the list appears and it must be exact, whithout clicking.

You are right. TPopupMenu has an event OnDropDown which could be used for this purpose because it fires when the popup menu is about to be shown. But the TMainMenu does not have it.

But look at how the MainMenu is used: Suppose your MainMenu contains several top-level items, among them "File". You first must click the "File" menu to drop down the list of its items, or you must press F10 or Alt for the same purpose. In each of these cases the OnClick event of the "File" menu fires. And you can use this to dynamically create the menu items.

I am attaching a simple demo. It contains a "File" menu and, below it, a "Recently opened" menu. When the "File" menu is clicked I erase the contents of the "Recently opened" submenu and create new items for it dynamically (here random file names for simplicity).

Unless I did not misunderstand your question, this shows that the functionality of a OnMouseEnter event of menu items can be achieved by the OnClick event of the associated top-level menu item.


[0] Message Index

Go to full version