MainMenu¶
Qualified name: delphivcl.MainMenu
- class MainMenu¶
Bases:
Menu
TMainMenu encapsulates a menu bar and its accompanying drop-down menus for a form. Use TMainMenu to provide the main menu for a form. To begin designing a menu, add a main menu to a form, and double-click the component. TMainMenu introduces properties and methods for merging the drop-down menus of the main menu with the main menu of another form. TMainMenu introduces properties and methods for assisting in the menu negotiation process of an OLE container.
Tip: To create a menu that users can configure at runtime, use the TActionMainMenuBar component with an action manager instead.
Methods
Connects methods to component events if they are named using the following pattern: Prefix_ComponentName_EventName.
Returns the main menu's accelerator table.
Returns the parent of a component.
Indicates whether the component has a parent to handle its filing.
Combines the main menu of one form with the main menu of another in non-MDI applications.
Populates an OLE menu with items from the main menu.
Associates the handle for an OLE menu with the main menu.
Reverses the merging of two menus in a non-MDI application.
Attributes
Determines whether the accelerator keys for menu items can be reset automatically.
Determines whether redundant separator bars are automatically removed from the menu.
Determines if the main menus of secondary forms merge with the main menu of the main form in non-MDI applications at runtime.
Determines the layout of the menu in Middle East locales.
ClassName
Returns the TObject.ClassName
ComObject
Specifies the interface reference implemented by the component.
Returns the owned component count
ComponentIndex
Indicates the position of the component in its owner's Components property array.
ComponentState
Describes the current state of the component, indicating when a component needs to avoid certain actions.
ComponentStyle
Governs the behavior of the component.
Returns an iterator over the owned components
DesignInfo
Contains information used by the Form designer.
Handle
Provides access to the Windows menu handle for the menu.
Lists the images that can appear beside individual menu items.
Items
Describes the elements of the menu.
Name
Specifies the name of the component as referenced in code.
Observers
Indicates the TObservers object added to the TComponent.
Callable[[Object, MenuItem, bool], None]:
Returns the Component Owner
Specifies whether the menu items are drawn by the application.
Indicates whether the BiDiMode property is inherited from the control that uses the menu.
Tag
Stores a NativeInt integral value as a part of a component.
VCLComObject
Represents information used internally by components that support COM.
WindowHandle
Provides access to the handle of the window that uses the menu.
- AutoHotkeys¶
Determines whether the accelerator keys for menu items can be reset automatically. Set AutoHotkeys to indicate whether the menu should automatically ensure that accelerator keys for its items are reset if necessary so that every menu item has an accelerator key and no two items have the same accelerator key. This ensures that menu items added dynamically at runtime can have accelerator keys that do not introduce conflicts. TMenu tries to preserve all existing accelerator key mappings when adjusting the accelerator keys, but may be forced to change some in order to ensure that every item has a unique accelerator. Before the menu is displayed, the menu checks and adjusts the accelerator key mappings if AutoHotkeys is maAutomatic. When AutoHotkeys is maManual, the menu does not alter the top-level menu items, but may adjust the accelerator keys for submenus, depending on the AutoHotkeys property of the menu item that is the parent of the submenu. When AutoHotkeys is maManual, an application can still adjust the menu items by calling the Items property’s RethinkHotkeys method. AutoHotkeys merely controls whether this adjustment occurs automatically.
Note: The AutoHotkeys property of a menu is linked to the AutoHotkeys property of the TMenuItems object that implements its Items property. Setting one sets the other.
- Type:
MenuAutoFlag
- AutoLineReduction¶
Determines whether redundant separator bars are automatically removed from the menu. Set AutoLineReduction to indicate whether the menu should automatically ensure that the menu does not start or end with a separator bar and that two separator bars do not appear next to each other. This ensures that menus built dynamically at runtime do not have separator bars in undesired positions. Before the menu is displayed, it removes superfluous separator bars when AutoLineReduction is maAutomatic. When AutoLineReduction is maManual, the menu does not remove separators from the top-level menu items, but may remove superfluous separators from submenus, depending on the AutoLineReduction property of the menu item that is the parent of the submenu. When AutoLineReduction is maManual, an application can still remove superfluous separators by calling the Items property’s RethinkLines method. AutoLineReduction merely determines whether this adjustment occurs automatically.
Note: The AutoLineReduction property of a menu is linked to the AutoLineReduction property of the TMenuItems object that implements its Items property. Setting one sets the other.
- Type:
MenuAutoFlag
- AutoMerge¶
Determines if the main menus of secondary forms merge with the main menu of the main form in non-MDI applications at runtime. To merge a form’s menus with the main menu in the main form, set the AutoMerge property of each main menu you want merged to true. Make sure that the AutoMerge property of the main menu of the main form (the one other menus are merged into) remains false. How menus merge depends on the value of the GroupIndex property for each menu item. If the application is an MDI application (the FormStyle properties are set so the main form is a parent form and subsequent forms are child forms), menu merging occurs automatically without using the AutoMerge property.
- Type:
bool
- BiDiMode¶
Determines the layout of the menu in Middle East locales. Set BiDiMode to control the layout of menu items. BiDiMode controls whether the menu items read from left to right or right to left.
- Type:
BiDiMode
- BindMethodsToEvents(prefix)¶
Connects methods to component events if they are named using the following pattern: Prefix_ComponentName_EventName. Example: def handle_button1_OnClick(Sender): pass The function returns a list of tuples. Each tuple contains the name of the component, the name of the event and the method object assigned to the event. Note that the prefix parameter is optional and will default to “handle_”.
- ComponentCount¶
Returns the owned component count
- Components¶
Returns an iterator over the owned components
- GetOle2AcceleratorTable(AccelTable: int, AccelCount: int, Groups: int) → None¶
Returns the main menu’s accelerator table. Call GetOle2AcceleratorTable to obtain a handle to an accelerator table for all menu items with a GroupIndex value that appears in the Groups parameter. The AccelTable parameter is set to the accelerator table handle, and the AccelCount is set to the number of entries in the table. GetOle2AcceleratorTable is used by OLE containers when merging menus.
- GetParentComponent()¶
Returns the parent of a component.
- HasParent()¶
Indicates whether the component has a parent to handle its filing.
- Images¶
Lists the images that can appear beside individual menu items. Use Images to hold the set of images that can appear beside menu items in the menu. Individual menu items set their ImageIndex property to indicate which image in the list appears to the left of the menu item caption. Images in the list should be 16x16.
Tip: If the application uses action lists, this property should be the value of the action list’s Images property. This way, menu items and buttons that do the same thing can display the same image.
- Type:
CustomImageList
- Merge(Menu: MainMenu) → None¶
Combines the main menu of one form with the main menu of another in non-MDI applications. Call Merge to merge another main menu with this one. Specify the menu you want merged with this menu as the Menu parameter. For example, to use the main menu of the first form in an application as the main menu for the application, call Merge to merge the main menu of any additional forms in the application with the main menu of the first form. Depending on the value of the GroupIndex property of menu items on the main menu, the merged menu items can replace menu items on the menu bar, or insert menu items into the menu bar. See GroupIndex for information on how to do these things. To merge and unmerge main menus automatically when other forms are displayed, change the value of the AutoMerge property to true on all forms whose menus should be merged in.
- OnChange¶
Callable[[Object, MenuItem, bool], None]:
- Owner¶
Returns the Component Owner
- OwnerDraw¶
Specifies whether the menu items are drawn by the application. Set OwnerDraw to true to indicate that the application will draw menu items in an OnDrawItem event handler. When OwnerDraw is true, menu items receive an OnMeasureItem and an OnDrawItem event when they need to be rendered on screen. Set OwnerDraw to false to accept the default drawing. When OwnerDraw is false, menu items display the caption with an optional image to the left (If the Images and ImageIndex properties are set). Owner-draw menus are useful for displaying the value that appears when selecting a menu item. For example, in a menu that allows users to choose a color, an owner-draw menu could display rectangles drawn in the designated color, rather than color names.
- Type:
bool
- ParentBiDiMode¶
Indicates whether the BiDiMode property is inherited from the control that uses the menu. By default, ParentBiDiMode is true, indicating that the layout of menu items follows the BiDiMode setting of the associated form or control. Change ParentBiDiMode to false to override the default BiDiMode setting and control the menu’s layout independently.
- Type:
bool
- PopulateOle2Menu(SharedMenu: int, Groups: int, Widths: int) → None¶
Populates an OLE menu with items from the main menu. Call PopulateOle2Menu to merge the menu items with GroupIndex values specified by the Groups parameter into the menu that uses the SharedMenu handle. PopulateOle2Menu appends all menu items in the specified groups to the menu, and increments the corresponding entries in the Widths array for every menu item appended. PopulateOle2Menu is used by OLE containers when merging menus.
Note: PopulateOle2Menu populates the menu specified by the SharedMenu parameter but does not set this as the OLE menu associated with the menu.
- SetOle2MenuHandle(Handle: int) → None¶
Associates the handle for an OLE menu with the main menu. Call SetOle2MenuHandle to temporarily replace the menu of a form with the menu represented by the Handle parameter. To restore the original menu, call SetOle2MenuHandle with the Handle parameter set to 0. SetOle2MenuHandle allows an OLE container to use menu items provided by an OLE server.