wpf-120440-controls-and-libraries-pdf-viewer-examples-interactivity-how-to-find-text-using-a-keyboard-shortcut.md
View Example: https://github.com/DevExpress-Examples/how-to-find-text-using-a-keyboard-shortcut
This example shows how to execute the Find Next action by pressing the F3 shortcut.
To do this, handle the PdfViewerControl.KeyDown event. If the F3 key is pressed, call the PdfViewerControl.FindText method and pass the search parameters represented by the TextSearchParameter object (e.g, search text, whole words, case sensitive).
using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.DocumentViewer;
namespace FindText {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
viewer.OpenDocument(@"..\..\Demo.pdf");
}
private void viewer_KeyDown(object sender, KeyEventArgs e) {
if (e.Key == Key.F3) {
TextSearchParameter parameters = new TextSearchParameter {
IsCaseSensitive = true,
WholeWord = true,
Text = "Viewer"
};
viewer.FindText(parameters);
}
}
}
}
Imports System.Windows
Imports System.Windows.Input
Imports DevExpress.Xpf.DocumentViewer
Namespace FindText
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
viewer.OpenDocument("..\..\Demo.pdf")
End Sub
Private Sub viewer_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.Key = Key.F3 Then
Dim parameters As TextSearchParameter = New TextSearchParameter With { _
.IsCaseSensitive = True, _
.WholeWord = True, _
.Text = "Viewer" _
}
viewer.FindText(parameters)
End If
End Sub
End Class
End Namespace
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FindText"
xmlns:dxpdf="http://schemas.devexpress.com/winfx/2008/xaml/pdf" x:Class="FindText.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<dxpdf:PdfViewerControl x:Name="viewer" KeyDown="viewer_KeyDown"/>
</Grid>
</Window>