Recent

Author Topic: OnMouseEnter event on MenuItem  (Read 3328 times)

PUNSOLA

  • Newbie
  • Posts: 2
OnMouseEnter event on MenuItem
« on: September 12, 2021, 01:13:18 pm »
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.


loaded

  • Hero Member
  • *****
  • Posts: 824
Re: OnMouseEnter event on MenuItem
« Reply #1 on: October 03, 2021, 01:25:42 pm »
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.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: OnMouseEnter event on MenuItem
« Reply #2 on: October 03, 2021, 01:27:02 pm »
Why don't you do this in the OnClick event?

Bart

PUNSOLA

  • Newbie
  • Posts: 2
Re: OnMouseEnter event on MenuItem
« Reply #3 on: October 08, 2021, 09:37:23 am »
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.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: OnMouseEnter event on MenuItem
« Reply #4 on: October 08, 2021, 11:17:44 am »
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.

 

TinyPortal © 2005-2018