MenuChanged

Description

Occurs when the ribbon bar in the MDI/MDIHelp frame window is initialized or rebuilt, for example, when the menu is first converted to ribbon bar and loaded in the window, or when the sheet window has switched and the corresponding menu has changed (which causes the ribbon bar to re-generate).

Event ID

Event ID

Objects

pbm_menuchanged

RibbonBar


Syntax

Long MenuChanged ( string oldmenu, string newmenu )

Argument

Argument

Description

oldmenu

The string representing the menu name of the frame window.

newmenu

The string representing the menu name of the sheet window that is currently opened.

The value will be the same as oldmenu, 1) when the sheet window does not have a menu, or 2) when the MDI frame window is opened for the first time.


Return Value

Long. Returns 1 if succeeds and -1 if an error occurs.

Usage

The DisplayMenuAsRibbonBar property must be enabled in order for this event to be triggered successfully. You will need to pass in the oldname parameter (the name of the menu for the MDI frame) and the newname parameter (the name of the menu associated with the active sheet (the currently opened sheet)), because several sheets can be open at the same time, and the menu associated with the active sheet will display as the menu of the frame, and whenever you switch the sheets, the menu (and the corresponding ribbon bar) of the frame will be initialized again.

To ensure the scripts that customize the ribbon bar are executed whenever the menu is switched, it is recommended to place the scripts (such as properties and functions related with the ribbon bar) in the MenuChanged event. If you place the scripts in the other events such as the MDI window Open event, the scripts may not be executed when the menu is switched.

If you have a custom MenuChanged event with the same name in versions earlier than PowerBuilder 2025, an event naming conflict may occur after upgrading to PowerBuilder 2025, causing related event and function calls to fail. It is recommended to rename the MenuChanged event name in the old version before upgrading the code.

Examples

The following scripts replace the "Edit" category with the category from an XML file:

RibbonCategoryItem  lr_Category
Integer             li_Return
String              ls_tag, ls_xml

ls_tag ="Edit"
li_Return = mdirbb_1.getitembytag(ls_tag, lr_Category)
If li_Return = 1 Then
 li_Return = mdirbb_1.replacecategorybyxml(lr_Category.itemhandle, ls_xml)
End If