Back to Devexpress

PictureEdit.PopupMenuShowing Event

windowsforms-devexpress-dot-xtraeditors-dot-pictureedit.md

latest4.1 KB
Original Source

PictureEdit.PopupMenuShowing Event

Fires when the context menu is about to be displayed.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event PopupMenuShowingEventHandler PopupMenuShowing
vb
<DXCategory("Events")>
Public Event PopupMenuShowing As PopupMenuShowingEventHandler

Event Data

The PopupMenuShowing event's data class is DevExpress.XtraEditors.Events.PopupMenuShowingEventArgs.

Remarks

The Picture Editor fires the PopupMenuShowing event when the context menu is about to be displayed and id the Properties.ShowMenu option is enabled. Handle the PopupMenuShowing event to customize the context menu or to prevent the menu from being displayed.

The following table lists event parameters:

PropertyDescription
e.PointAllows you to obtain the position at which the editor is right-clicked.
e.PopupMenuAllows you to access and customize the menu. The menu is represented by a DXPopupMenu object.
e.RestoreMenuAllows you to specify whether to restore the context menu to the default settings after the menu has been displayed.
e.CancelAllows you you to prevent the menu from being displayed.

The following example adds the “Properties” menu item to the Picture Editor’s context menu if the editor displays an image:

csharp
public Form1() {
    InitializeComponent();
    pictureEdit1.PopupMenuShowing += PictureEdit1_PopupMenuShowing;
}

void PictureEdit1_PopupMenuShowing(object sender, DevExpress.XtraEditors.Events.PopupMenuShowingEventArgs e) {
    e.RestoreMenu = true;
    if(pictureEdit1.EditValue != null)
        e.PopupMenu.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Properties",
                              new EventHandler(OnProperties_Click),
                              svgImageCollection1["properties"],
                              DevExpress.Utils.Menu.DXMenuItemPriority.Normal));
}

void OnProperties_Click(object sender, EventArgs e) {
  // Do something when a user clicks the "Properties" item.
}
vb
Public Sub New()
    InitializeComponent()
    AddHandler pictureEdit1.PopupMenuShowing, AddressOf PictureEdit1_PopupMenuShowing
End Sub

Private Sub PictureEdit1_PopupMenuShowing(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Events.PopupMenuShowingEventArgs)
  e.RestoreMenu = True
    If pictureEdit1.EditValue IsNot Nothing Then
        e.PopupMenu.Items.Add(New DevExpress.Utils.Menu.DXMenuItem("Properties", New EventHandler(AddressOf OnProperties_Click), svgImageCollection1("properties"), DevExpress.Utils.Menu.DXMenuItemPriority.Normal))
    End If
End Sub

Private Sub OnProperties_Click(ByVal sender As Object, ByVal e As EventArgs)
  ' Do something when a user clicks the "Properties" item.
End Sub

The image below shows the result:

The PopupMenuShowing event is equivalent to the RepositoryItemPictureEdit.PopupMenuShowing event.

See Also

PopupMenuShowing

ShowMenu

PictureEdit Class

PictureEdit Members

DevExpress.XtraEditors Namespace