|
- 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
Menus and menu options: Tips & Tricks
This page presents some operations specific to the menus and to the menu options: Remarks: - For more details about the menus and menu options, see:
- All these "Tips & Tricks" can be used with the main menus and with the popup menus unless stated otherwise.
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: - Select a menu option.
- Open the "Style" tab in the description window of menu options ("Option description" from the popup).
- 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).
Special case: Menu in XP styleOnly 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. 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".
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? - Display the code of the element (control or window) associated with the context menu ("Code" in the context menu of element).
- Click the link "Add other events to xxx" at the bottom of the window code, after the last event.
- In the list of optional events, select "Displaying context menu" and validate.
- 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". - Open the code of "EDT_MyControl" ("Code" in the context menu of the control).
- 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.
- 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. - Display the code of "TABLE_MyTable" ("Code" from the popup menu of control).
- 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.
- 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
This page is also available for…
|
|
|
|
|
|
|