ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Developing an application or website / Controls, windows and pages / Drop-down menus / WINDEV and WINDEV Mobile
  • Overview
  • Tips and tricks
  • Replacing the caption of a menu option by the control content
  • Adding help to a menu option
  • Customizing the menu appearance
  • Making the main menu of a window invisible
  • Running code before displaying the context menu
  • Displaying a context menu via a left click
  • Dissociating a context menu from a control or from a window
  • Retrieving the number of the Table row and column on which a right click is performed
  • Changing the context menu according to the element selected in a TreeView control
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Tips and tricks

Replacing the caption of a menu option by the control content

To do so:
  • retrieve the control content.
  • change the text of the menu option with the Caption property or the MenuLabel function.
Examples:
  • The caption of "MyOption" must correspond to the value typed in "MyControl".
    MyOption.Caption = MyControl
    // Equivalent to: MenuLabel(MyOption, MyControl)
  • The caption of "MyOption" must correspond to the content of the cell belonging to "COL_MyColumn" and to the row selected by the user in the Table control named "TABLE_MyTable":
    MyOption.Caption = COL_MyColumn[TableSelect(TABLE_MyTable)]
    // Equivalent to:
    // MenuLabel(MyOption, COL_MyColumn[TableSelect(TABLE_MyTable)])

Adding help to a menu option

To explain the operating mode of each menu option, a help message can be displayed in the status bar of window when an option is highlighted.
How to proceed?
This help message is typed in the "Help" tab of the description window of menu options ("Option description" in the context menu). This help message can be multilingual.
Remark: This help message can be modified through programming with the Message function or with the Message property.

Customizing the menu appearance

To customize the menu appearance, all you have to do is customize the style of an option in this menu. These modifications will be automatically applied to all menu options.
You can customize:
  • the background color of a menu.
  • the font (size, color, ...) of menu options.
  • the background color of hovered option.
  • the font (size, color, ...) of the option hovered by the mouse cursor.
To customize the menu appearance:
  1. Select a menu option.
  2. Open the "Style" tab in the description window of menu options ("Option description" from the popup).
  3. To customize:
    • the background color of menu: select "Option background" in the "Element" combo box and select the background color of the option.
    • the font of menu options: select "Option text" in the "Element" combo box and select the font characteristics (attributes, size, color, ...)
    • the background color of hovered option: select "Option background (rollover)" in the "Element" combo box and select the background color of the option hovered by the mouse cursor.
Remark: The background color or the text color can be:
  • a preset color. Select this color among the ones proposed in the "Color" combo box.
  • a custom color. Define this color with the color picker ("..." button on the right of "Color" combo box).
For example:
Background color of options and text color
Special case: Menu in XP style
Only the characteristics of the font defined for the menu options will be taken into account if the menu uses the XP style. For more details, see Using the XP style in your windows.
Universal Windows 10 App You cannot customize the menu appearance.

Making the main menu of a window invisible

To make the main menu invisible, all you have to do is make all "main" options of the menu invisible.
Example: The "main" options of the following menu are "Files" and "Prints".
Main options
To hide this main menu, enter the following code:
// Make the "Files" and "Prints" options invisible
Files.Visible = False
Prints.Visible = False
// Equivalent to:
// MenuInvisible(Files)
// MenuInvisible(Prints)

Running code before displaying the context menu

To run code before displaying the context menu, simply add the optional event named "Display context menu" into the code of the element (control or window) associated with the context menu.
How to?
  1. Display the code of the element (control or window) associated with the context menu ("Code" in the context menu of element).
  2. Click the link "Add other events to xxx" at the bottom of the window code, after the last event.
  3. In the list of optional events, select "Displaying context menu" and validate.
  4. In this optional event, write the code that will be run before displaying the context menu.

Displaying a context menu via a left click

To display a context menu via a left click, simply simulate the action of a right click in the optional event named "Left button down" of an element (control or window).
In order for the popup menu to be displayed during a left click (and not during a right click), the element (control or window) must not be associated by default with a popup menu.
Example: The operations required to open a context menu when left-clicking are illustrated in the following example: The "MyMenu" context menu appears only when you left-click on "EDT_MyControl".
  1. Open the code of "EDT_MyControl" ("Code" in the context menu of the control).
  2. Click the "Add other events to xxx" link at the bottom of the window code, after the last event.
    In the list of optional events, select "Left button down" and confirm.
  3. In this optional event, write the following code:
    // Associate the context menu with the control
    EDT_MyControl.ContextMenu = MyMenu
    // Simulate a right click on the button to call
    // the context menu
    SendMessage(Handle(MySelf), 516, 0, 0)
    SendMessage(Handle(MySelf), 517, 0, 0)
    // Dissociate the context menu from the control
    EDT_MyControl.ContextMenu = ""

Dissociating a context menu from a control or from a window

To dissociate a context menu from a control or a window, use the ContextMenu property and pass an empty character string ("") as parameter.
Example
// Dissociate the context menu from the control
EDT_MyControl.ContextMenu = ""
Remark: If a system popup menu is available, this popup menu will replace the custom popup menu.

Retrieving the number of the Table row and column on which a right click is performed

To retrieve the number of the Table row and column selected by a right click before displaying the context menu, use TableInfoXY in the optional event "Right button down".
Example: The operations required to retrieve the number of the row and column selected by a right mouse click are illustrated in the following example: The context menu "MyMenu" is associated with the Table control named "TABLE_MyTable". This menu is used to handle the content of the cell from which the context menu is opened.
The selected cell is colored in blue before displaying the popup menu.
  1. Display the code of "TABLE_MyTable" ("Code" from the popup menu of control).
  2. Click the "Add other events to xxx" link at the bottom of the window code, after the last event.
    In the list of optional events, select "Right button down" and confirm.
  3. In this optional event, write the following code:
    // Retrieve the row and column selected via a right click
    NumSelectedRow is int
    NumSelectedCol is int
    NumSelectedRow = TableInfoXY(MySelf, tiLineNumber, MouseXPos(), MouseYPos())
    NumSelectedCol = TableInfoXY(MySelf, tiColNumber, MouseXPos(), MouseYPos())
    // Modify the color of the selected cell
    TABLE_MyTable [NumSelectedRow][NumSelectedCol].BackgroundColor = LightBlue
WINDEV

Changing the context menu according to the element selected in a TreeView control

To dynamically change the context menu when selecting an item in a TreeView control, use the ContextMenu property. This property must be used when intercepting a right mouse click on the TreeView control (optional event "Right click").
Example: The operations required to dynamically change a context menu when right-clicking on an element on a TreeView control are presented in the following example:
The following context menus are associated with the "TREE_Groups" control:
  • ctxUser: used to handle the users listed in the TreeView control.
  • ctxGroup: used to handle the groups of users listed in the TreeView control.
    Each node of the TreeView control represents a group of users. Each leaf of the TreeView control represents a user.
  1. Display the code of "TREE_Groups" ("Code" from the popup menu of the control).
  2. Position your cursor in the optional event "Right click of TREE_Groups".
  3. In this event, write the following code:
    // -- Right click of TREE_Groups
    // According to the type of the element selected in the TreeView control,
    // the context menu to display is changed
    nElementType = TreeTypeItem(TREE_Groups, TreeSelect(TREE_Groups))
     
    SWITCH nElementType
    CASE tvLeaf // It's a user
    TREE_Groups.PopupMenu = ctxUser
    CASE tvNode // It's a group of users
    TREE_Groups.PopupMenu = ctxGroup
    OTHER CASE // If an error occurs
    TREE_Groups.PopupMenu = ""
    END
Result:
First context menu of an elementSecond context menu of an element
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/20/2023

Send a report | Local help