Back to Devexpress

How to: Find Text Using a Keyboard Shortcut

windowsforms-119937-controls-and-libraries-pdf-viewer-examples-interactivity-how-to-find-text-using-a-keyboard-shortcut.md

latest2.7 KB
Original Source

How to: Find Text Using a Keyboard Shortcut

  • Nov 13, 2018
  • 2 minutes to read

This example shows how to execute the Find Next action by pressing the F3 shortcut, after an end-user has specified text search options in the Find Text dialog.

To do this, handle the PdfViewer.KeyDown event. If the F3 key is pressed, call the overloaded PdfViewer.FindText method and pass the text to search and search parameters obtained from the Find Text dialog to this method.

The text search settings (e.g, search text, whole words, case sensitive) applied by an end-user in the Find Text dialog can be accessed using the PdfViewer.FindDialogOptions property.

csharp
using DevExpress.Pdf;
using DevExpress.XtraPdfViewer;
using System;
using System.Windows.Forms;

namespace FindTextUsingShortcut {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            pdfViewer1.LoadDocument(@"..\..\Report.pdf");
        }

        private void pdfViewer1_KeyDown(object sender, KeyEventArgs e) {
            if (e.KeyData == Keys.F3) {
                PdfTextSearchParameters parameters = new PdfTextSearchParameters();
                PdfFindDialogOptions options = pdfViewer1.FindDialogOptions;
                parameters.CaseSensitive = options.CaseSensitive;
                parameters.WholeWords = options.WholeWords;
                pdfViewer1.FindText(options.Text, parameters);
            }
        }
    }
}
vb
Imports DevExpress.Pdf
Imports DevExpress.XtraPdfViewer
Imports System
Imports System.Windows.Forms

Namespace FindTextUsingShortcut
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            pdfViewer1.LoadDocument("..\..\Report.pdf")
        End Sub

        Private Sub pdfViewer1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles pdfViewer1.KeyDown
            If e.KeyData = Keys.F3 Then
                Dim parameters As New PdfTextSearchParameters()
                Dim options As PdfFindDialogOptions = pdfViewer1.FindDialogOptions
                parameters.CaseSensitive = options.CaseSensitive
                parameters.WholeWords = options.WholeWords
                pdfViewer1.FindText(options.Text, parameters)
            End If
        End Sub
    End Class
End Namespace