xtd - Reference Guide 0.2.0
xtd::forms::context_menu Class Reference

#include <context_menu.h>

Definition

Represents a shortcut menu.

Namespace
xtd::forms
Library
xtd.forms

Constructors

 context_menu ()
 Initialize context_menu class. More...
 
 context_menu (const std::vector< menu_item_ref > &menu_items)
 Initialize a new instance of context_menu class. More...
 

Ppublic methods

void show (const xtd::forms::control &control, const xtd::drawing::point &pos)
 Displays the shortcut menu at the specified position. More...
 

Protected methods

intptr_t create_menu_handle () override
 Creates a new handle to the Menu. More...
 
void destroy_menu_handle (intptr_t handle) override
 Destroys the handle to the Menu. More...
 
void on_item_added (size_t pos, menu_item_ref item) override
 
void on_item_removed (size_t pos, menu_item_ref item) override
 

Additional Inherited Members

- Public Types inherited from xtd::forms::menu
using menu_item_collection = layout::arranged_element_collection< menu_item_ref >
 Represents a collection of menu_item objects. More...
 
- Static Public Attributes inherited from xtd::forms::menu
static constexpr const int find_handle = 0
 Specifies that the find_menu_item(int32_t, intptr_t) method should search for a handle. More...
 
static constexpr const int find_shortcut = 1
 Specifies that the find_menu_item(int32_t, intptr_t) method should search for a shortcut. More...
 
- Public Member Functions inherited from xtd::forms::menu
intptr_t handle () const
 Gets a value representing the window handle for the menu. More...
 
virtual bool is_parent () const
 Gets a value indicating whether this menu contains any menu items. More...
 
const menu_itemmdi_list_item () const
 Gets a value indicating the menu_item that is used to display a list of multiple document interface (MDI) child forms. More...
 
const menu_item_collectionmenu_items () const
 Gets a value indicating the collection of menu_item objects associated with the menu. More...
 
menu_item_collectionmenu_items ()
 Gets a value indicating the collection of menu_item objects associated with the menu. More...
 
menumenu_items (const menu_item_collection &value)
 Sets a value indicating the collection of menu_item objects associated with the menu. More...
 
const xtd::ustringname () const
 Gets the name of the menu. More...
 
menuname (const xtd::ustring &value)
 Sets the name of the menu. More...
 
std::any tag () const
 Gets user-defined data associated with the control. More...
 
menutag (std::any value)
 Sets user-defined data associated with the control. More...
 
bool equals (const menu &) const noexcept override
 
bool equals (const object &) const noexcept override
 Indicates whether the current object is equal to another object of the same type. More...
 
std::optional< std::reference_wrapper< context_menu > > get_context_menu () const
 Gets the context_menu that contains this menu. More...
 
std::optional< std::reference_wrapper< main_menu > > get_main_menu () const
 Gets the main_menu that contains this menu. More...
 
virtual void merge_menu (const menu &menu_src)
 Merges the MenuItem objects of one menu with the current menu. More...
 
xtd::ustring to_string () const noexcept override
 Returns a string that represents the menu control. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
- Public Member Functions inherited from xtd::iequatable< menu >
virtual bool equals (const menu &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 
- Protected Attributes inherited from xtd::forms::menu
friend menu_item
 
- Protected Member Functions inherited from xtd::forms::menu
 menu ()
 Initializes a new instance of the Menu class. More...
 
 menu (const menu_item_collection &items)
 Initializes a new instance of the Menu class. More...
 
void clone_menu (const menu &menu_src)
 Copies the menu that is passed as a parameter to the current menu. More...
 
- Protected Member Functions inherited from xtd::forms::component
 component ()=default
 Initialises a new instance of the component class. More...
 
virtual bool can_raise_events () const
 Gets a value indicating whether the component can raise an event. More...
 
bool design_mode () const
 Gets a value that indicates whether the component is currently in design mode. More...
 

Constructor & Destructor Documentation

◆ context_menu() [1/2]

xtd::forms::context_menu::context_menu ( )

Initialize context_menu class.

◆ context_menu() [2/2]

xtd::forms::context_menu::context_menu ( const std::vector< menu_item_ref > &  menu_items)

Initialize a new instance of context_menu class.

Parameters
menu_itemsAn array of menu_item objects that will be added to the main_menu.

Member Function Documentation

◆ create_menu_handle()

intptr_t xtd::forms::context_menu::create_menu_handle ( )
overrideprotectedvirtual

Creates a new handle to the Menu.

Returns
A handle to the menu if the method succeeds; otherwise, 0.

Implements xtd::forms::menu.

◆ destroy_menu_handle()

void xtd::forms::context_menu::destroy_menu_handle ( intptr_t  handle)
overrideprotectedvirtual

Destroys the handle to the Menu.

Parameters
handleA handle to the menu.

Reimplemented from xtd::forms::menu.

◆ show()

void xtd::forms::context_menu::show ( const xtd::forms::control control,
const xtd::drawing::point pos 
)

Displays the shortcut menu at the specified position.

Parameters
controlA xtd::forms::control that specifies the control with which this shortcut menu is associated.
posA xtd::drawing::point that specifies the coordinates at which to display the menu. These coordinates are specified relative to the client coordinates of the control specified in the control parameter.
Remarks
Typically, a xtd::forms::context_menu is displayed when the user clicks the right mouse button on a control or area of the form that the xtd::forms::context_menu is bound to. You can use this method to manually display the shortcut menu at a specific location and bind it with a specific control. This method does not return until the menu is dismissed.

The documentation for this class was generated from the following file: