|
|
|
|
|
- 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 context 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
- 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. Note: This help message can be modified programmatically using the Message function or 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:
- menu background color: select "Option background" in the "Element" combo and select the option background color.
- menu option font: select "Option Text" in the "Element" combo and select font characteristics (attributes, size, color, etc.)
- background color of hovered option: select "Option background (hover)" in the "Element" combo and select the background color of the hovered option.
Note: The background or 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 with XPlook 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. 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:
Queue.Visible = False
Impressions.Visible = False
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 context 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 context menu. Example: The operations required to display a context menu with a left-click are illustrated by the following example: The "MyMenu" context menu is only displayed when left-clicking on the "SAI_MyChamp" Edit control. - Open the code of "EDT_MyControl" ("Code" in the context menu of the control).
- 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 "Left button down" and validate.
- 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 = "" Note: If a system context menu is available, this context menu will replace the custom context 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-click are illustrated by the following example: The "MyMenu" context menu is associated with the "TABLE_MaTable" field.. 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 context menu. - Display the code of "TABLE_MyTable" ("Code" in the context menu of the control).
- 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 the "Right button down" event and validate.
- 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|