windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-01f87239.md
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
public event PdfPopupMenuShowingEventHandler PopupMenuShowing
Public Event PopupMenuShowing As PdfPopupMenuShowingEventHandler
The PopupMenuShowing event's data class is PdfPopupMenuShowingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| ItemLinks | Gets the collection of popup menu links displayed when the menu is being invoked. |
| Menu | Obsolete. Provides access to a popup menu that is being invoked. |
| PopupMenuKind | Gets the type of a particular popup menu shown for the PDF Viewer. |
The PDF Viewer UI includes the following pre-defined popup menus:
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.
This example demonstrates how to add a custom item to the popup menu.
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");
}
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
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:
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";
}
}
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
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.
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);
}
}
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
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:
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();
}
}
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