Back to Devexpress

SvgImageBox.PopupMenuShowing Event

windowsforms-devexpress-dot-xtraeditors-dot-svgimagebox-9cbbb882.md

latest4.5 KB
Original Source

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.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public event SvgImagePopupMenuShowingEventHandler PopupMenuShowing
vb
Public Event PopupMenuShowing As SvgImagePopupMenuShowingEventHandler

Event Data

The PopupMenuShowing event's data class is SvgImagePopupMenuShowingEventArgs. The following properties provide information specific to this event:

PropertyDescription
AllowGets or sets whether to allow the menu to be displayed.
ItemGets the clicked item.
MenuGets or sets the popup menu that is about to be displayed
PointGets 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.

csharp
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;
}
vb
Private Sub SvgImageBox1_PopupMenuShowing(sender As Object, e As DevExpress.XtraEditors.SvgImagePopupMenuShowingEventArgs) Handles SvgImageBox1.PopupMenuShowing
    Dim control As SvgImageBox = TryCast(sender, SvgImageBox)
    Dim item As SvgImageItem = e.Item
    If item Is Nothing Then item = control.GetItemsAt(e.Point).FirstOrDefault()
    If item Is Nothing Then Return
    Dim menuItemCaption As String = If(item.ActualVisible, "Hide", "Show")
    Dim menuItem As DXMenuItem = New DXMenuCheckItem(menuItemCaption)
    AddHandler menuItem.Click, AddressOf MenuItem_Click
    menuItem.Tag = item
    e.Menu.Items.Add(menuItem)
End Sub

Private Sub MenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim menuItem As DXMenuItem = TryCast(sender, DXMenuItem)
    Dim item As SvgImageItem = TryCast(menuItem.Tag, SvgImageItem)
    item.Visible = Not item.Visible
End Sub
Class

See Also

SvgImageBox Class

SvgImageBox Members

DevExpress.XtraEditors Namespace