On this page
Guides
Custom Menu
The CPDFView
supports a right-click menu feature. Right-clicking within the CPDFView
area will trigger a custom menu.
You can set different custom menus for users in various contexts. For instance, setting the page zoom level when right-clicking in a blank area, enabling copy options when right-clicking on text, images, or annotations, etc.
The steps for setting up a custom menu are as follows:
- Register for the custom menu event.
- Take action based on the command type (
e.CommandType
). When the command type isContext
, create a context menu and add menu items (Copy, Cut, Paste, Delete). - When the command type is a basic command (Copy, Cut, Paste, Delete), directly call the
e.DoCommand()
method to execute the corresponding command.
This example shows how to create a custom menu:
C#
// Register custom menu event
myCPDFViewer.AnnotCommandHandler += PdfViewer_AnnotCommandHandler;
private void myCPDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
{
// Operate based on the command type (`e.CommandType`). When the command type is `Context`, create a context menu and add menu items (Copy, Cut, Paste, Delete).
switch (e.CommandType)
{
case CommandType.Context:
e.Handle = true;
e.PopupMenu = new ContextMenu();
e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
break;
// When the command type is a basic command (Copy, Cut, Paste, Delete), directly invoke the `e.DoCommand()` method to execute the corresponding command.
case CommandType.Copy:
case CommandType.Cut:
case CommandType.Paste:
case CommandType.Delete:
e.DoCommand();
break;
default:
break;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28