SvgImageBox.PopupMenuShowing Event
Fires when a user right-clicks with the mouse. Allows you to display a context menu for image items.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.Utils.v24.2.dll
Declaration
Event Data
The PopupMenuShowing event's data class is SvgImagePopupMenuShowingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Allow | Gets or sets whether to allow the menu to be displayed. |
Item | Gets the clicked item. |
Menu | Gets or sets the popup menu that is about to be displayed |
Point | Gets the position where the menu is to be invoked. |
Remarks
When a user right-clicks the image, the control creates an empty context menu and fires the PopupMenuShowing event. You can handle this event to add custom commands to the menu (the e.Menu event parameter).
The e.Item parameter specifies the currently hovered item.
The PopupMenuShowing event also fires when a user right clicks a hidden item or an empty space. In this case, the e.Item event parameter is null.
The control does not show a context menu unless you populate it with commands (DXMenuItem objects).
Example
The following example shows how to handle the SvgImageBox.PopupMenuShowing
event to display a context menu for image items. The menu contains commands to hide and show image items.
private void svgImageBox1_PopupMenuShowing(object sender, DevExpress.XtraEditors.SvgImagePopupMenuShowingEventArgs e) {
SvgImageBox control = sender as SvgImageBox;
SvgImageItem item = e.Item;
// If you hover over a hidden item, the e.Item event parameter returns null.
// Use the GetItemsAt method to get a hidden item at the clicked point.
if (item == null)
item = control.GetItemsAt(e.Point).FirstOrDefault();
if (item == null) return;
string menuItemCaption = item.ActualVisible ? "Hide" : "Show";
DXMenuItem menuItem = new DXMenuCheckItem(menuItemCaption);
menuItem.Click += MenuItem_Click;
menuItem.Tag = item;
e.Menu.Items.Add(menuItem);
}
private void MenuItem_Click(object sender, EventArgs e) {
DXMenuItem menuItem = sender as DXMenuItem;
SvgImageItem item = menuItem.Tag as SvgImageItem;
item.Visible = !item.Visible;
}