Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Find Text Using a Keyboard Shortcut

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);
            }
        }
    }
}