Back to Devexpress

PdfViewer.PopupMenuShowing Event

windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-01f87239.md

latest8.9 KB
Original Source

PdfViewer.PopupMenuShowing Event

Occurs when a popup menu is about to be displayed for the PdfViewer.

Namespace : DevExpress.XtraPdfViewer

Assembly : DevExpress.XtraPdfViewer.v25.2.dll

NuGet Package : DevExpress.Win.PdfViewer

Declaration

csharp
public event PdfPopupMenuShowingEventHandler PopupMenuShowing
vb
Public Event PopupMenuShowing As PdfPopupMenuShowingEventHandler

Event Data

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

PropertyDescription
ItemLinksGets the collection of popup menu links displayed when the menu is being invoked.
MenuObsolete. Provides access to a popup menu that is being invoked.
PopupMenuKindGets the type of a particular popup menu shown for the PDF Viewer.

Remarks

The PDF Viewer UI includes the following pre-defined popup menus:

  • Context menus for page content, bookmarks, thumbnails, and other elements.
  • Static menus available in various toolbars and panels.

Handle the PdfViewer.PopupMenuShowing event to customize popup menus. Check the PopupMenuKind argument to determine the menu type. Use the ItemLinks argument to access the command collection.

Add a PopUp Menu Item

This example demonstrates how to add a custom item to the popup menu.

csharp
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraPdfViewer;
using System.Windows.Forms;
//...

void pdfViewer1_PopupMenuShowing(object sender, PdfPopupMenuShowingEventArgs e) {

    // Create a bar button item.
    BarButtonItem browseBarButton = new BarButtonItem();
    browseBarButton.Caption = "Custom Item";

    // Insert the bar button item 
    // and start a new group.
    e.ItemLinks.Add(browseBarButton, true);

    // Handle the bar button click event.
    browseBarButton.ItemClick += browseBarButton_ItemClick;
}

void browseBarButton_ItemClick(object sender, ItemClickEventArgs e) {
    MessageBox.Show("ItemClick event fires");
}
vb
Imports System.Windows.Forms
Imports DevExpress.XtraPdfViewer
Imports DevExpress.XtraBars

'...
Private Sub pdfViewer1_PopupMenuShowing(ByVal sender As Object, ByVal e As PdfPopupMenuShowingEventArgs) Handles pdfViewer1.PopupMenuShowing
    ' Create a bar button item.
    Dim browseBarButton As New BarButtonItem()
    browseBarButton.Caption = "Custom Item"

    ' Insert the bar button item into the PDF Viewer popup menu and start a new group.
    e.ItemLinks.Add(browseBarButton, True)

    ' Handle the bar button click event.
    AddHandler browseBarButton.ItemClick, AddressOf browseBarButton_ItemClick
End Sub

Private Sub browseBarButton_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    MessageBox.Show("ItemClick event fires")
End Sub

Modify a PopUp Menu Item

Access the menu item collection and call its GetPdfViewerBarItemLink method to obtain an item by its command ID. Use the returned BarItemLink object to change the menu item parameters.

The code sample below shows how to change a caption of a built-in menu item:

csharp
using DevExpress.XtraPdfViewer;
using DevExpress.XtraPdfViewer.Commands;
using DevExpress.XtraPdfViewer.Extensions;
//...

void pdfViewer1_PopupMenuShowing(object sender, PdfPopupMenuShowingEventArgs e)
{
    // Retrieve a Hand Tool item
    // in the Page Content menu.
    if (e.PopupMenuKind == PdfPopupMenuKind.PageContent)
    {
        var handToolItem =
            e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.HandTool);

        // Change the item caption.
        handToolItem.Caption = "Custom Caption";
    }
}
vb
Imports DevExpress.XtraPdfViewer
Imports DevExpress.XtraPdfViewer.Commands
Imports DevExpress.XtraPdfViewer.Extensions
'...

Private Sub pdfViewer1_PopupMenuShowing(ByVal sender As Object, ByVal e As PdfPopupMenuShowingEventArgs)
    If e.PopupMenuKind = PdfPopupMenuKind.PageContent Then
        Dim handToolItem = e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.HandTool)
        handToolItem.Caption = "Custom Caption"
    End If
End Sub

Remove a PopUp Menu Item

Access the menu item collection and call its GetPdfViewerBarItemLink method to obtain an item by its command ID. Call the Remove(T) method and pass the obtain menu item as a parameter to remove this item.

This example shows how to remove specific items from the page content popup menu.

View Example

csharp
using DevExpress.XtraPdfViewer;
using DevExpress.XtraPdfViewer.Commands;
using DevExpress.XtraPdfViewer.Extensions;
//...

void pdfViewer1_PopupMenuShowing(object sender, PdfPopupMenuShowingEventArgs e)
{
    // Remove Rotate Clockwise and Rotate Counterclockwise items
    // from the Page Content popup menu.
    if (e.PopupMenuKind == PdfPopupMenuKind.PageContent)
    {
        var rotateClockwiseItem =
            e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.RotatePageClockwise);
        e.ItemLinks.Remove(rotateClockwiseItem);

        var rotateCounterclockwiseItem =
            e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.RotatePageCounterclockwise);
        e.ItemLinks.Remove(rotateCounterclockwiseItem);
    }
}
vb
Imports DevExpress.XtraPdfViewer
Imports DevExpress.XtraPdfViewer.Commands
Imports DevExpress.XtraPdfViewer.Extensions

Private Sub pdfViewer1_PopupMenuShowing(ByVal sender As Object, ByVal e As PdfPopupMenuShowingEventArgs)

    If e.PopupMenuKind = PdfPopupMenuKind.PageContent Then
        Dim rotateClockwiseItem = e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.RotatePageClockwise)
        e.ItemLinks.Remove(rotateClockwiseItem)

        Dim rotateCounterclockwiseItem = e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.RotatePageCounterclockwise)
        e.ItemLinks.Remove(rotateCounterclockwiseItem)
    End If
End Sub

Hide the Pop-Up Menu

Clear all items from the item collection to hide a popup menu.

The code sample below hides the pop-up menu for a bookmark tree:

View Example

csharp
using DevExpress.XtraPdfViewer;
using DevExpress.XtraPdfViewer.Commands;
using DevExpress.XtraPdfViewer.Extensions;
//...

void pdfViewer1_PopupMenuShowing(object sender, PdfPopupMenuShowingEventArgs e)
{
    // Hide the popup menu for the bookmark tree.
    if (e.PopupMenuKind == PdfPopupMenuKind.BookmarkTree)
    {
        e.ItemLinks.Clear();
    }
}
vb
Imports DevExpress.XtraPdfViewer
Imports DevExpress.XtraPdfViewer.Commands
Imports DevExpress.XtraPdfViewer.Extensions

Private Sub pdfViewer1_PopupMenuShowing(ByVal sender As Object, ByVal e As PdfPopupMenuShowingEventArgs)
    If e.PopupMenuKind = PdfPopupMenuKind.BookmarkTree Then
        e.ItemLinks.Clear()
    End If
End Sub

See Also

PdfViewer Class

PdfViewer Members

DevExpress.XtraPdfViewer Namespace