How to: Remove Items from the Popup Menu

  • 2 minutes to read

The PDF Viewer has several types of popup menus that can be invoked by an end-user for bookmark options, bookmark tree, page content, thumbnail and thumbnail options.

This example shows how to hide the popup menu for the bookmark tree and remove specific items from the page content popup menu.

To customize items of the PDF Viewer's popup menu, handle the PdfViewer.PopupMenuShowing event. This event fires every time an end-user opens a popup menu in the PDF Viewer.

Each popup menu type has a unique set of bar items that are located in the bar item link collection. To access this collection, check the popup menu type using the PdfPopupMenuShowingEventArgs.PopupMenuKind property and use the PdfPopupMenuShowingEventArgs.ItemLinks property.

To hide a popup menu, clear all items from the bar item link collection.

To remove an item from a popup menu, use the PdfViewerBarItemLinkCollectionExtensions.GetPdfViewerBarItemLink method. It allows you to access the required menu items by it's command id.

using System.Windows.Forms;
using DevExpress.XtraPdfViewer;
using DevExpress.XtraBars;
using DevExpress.XtraPdfViewer.Extensions;

namespace CustomPopupMenu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            pdfViewer1.LoadDocument("..\\..\\Demo.pdf");
        }

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

            // Remove Rotate Clockwise and Rotate Counterclockwise items from the Page Content popup menu.
            if (e.PopupMenuKind == PdfPopupMenuKind.PageContent)
            {
             e.ItemLinks.Remove(e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.RotatePageClockwise));
            e.ItemLinks.Remove(e.ItemLinks.GetPdfViewerBarItemLink(PdfViewerCommandId.RotatePageCounterclockwise));

            }
        }
    }
}