Page 1 of 1

PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Posted: Thu Jan 23, 2020 2:01 am
by IntegraMike
Hello, we're working on doing some custom hotkey work for the PdfFreeTextAnnotations, specifically when they're in text edit mode but having some issues trapping/overriding the default hotkeys. We're specifically looking at CTRL+I and CTRL+B right now but are not seeing where the events are for the editor that handle keyboard input. If you could point us in the right direction we would appreciate it.

Thanks!
Mike

Re: PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Posted: Thu Jan 23, 2020 12:12 pm
by Alex
Hello Mike,

Do you use WinForms or WPF?

Best regards, Alexander

Re: PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Posted: Fri Jan 24, 2020 3:41 am
by IntegraHarlan
Hi Alexander,
We are using WinForms

Thanks

Re: PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Posted: Fri Jan 24, 2020 9:59 am
by Alex
Hi Harlan,

Thank you for information.

For solving your task you need to create manager, which stores and manages settings for interaction areas of visual tool, implement necessary logic in manager and specify that manager must work with PDF annotation tool:

Code: Select all

/// <summary>
/// Stores and manages settings for interaction areas of visual tool.
/// </summary>
public class TextBoxInteractionAreaAppearanceManager : InteractionAreaAppearanceManager
{

    /// <summary>
    /// Initializes a new instance of the <see cref="TextBoxInteractionAreaAppearanceManager"/> class.
    /// </summary>
    public TextBoxInteractionAreaAppearanceManager()
    {
    }



    /// <summary>
    /// Sets the text box settings.
    /// </summary>
    /// <param name="textBox">The text box of interactive object (PdfFreeTextAnnotation, etc).</param>
    public override void SetTextBoxSettings(RichTextBox textBox)
    {
        base.SetTextBoxSettings(textBox);

        if (textBox != null)
        {
            // subscribe to the KeyDown event of text box
            textBox.KeyDown += TextBox_KeyDown;
        }
    }

    /// <summary>
    /// Key is pressed in text box.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
    private void TextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Modifiers == Keys.Control)
        {
            switch (e.KeyCode)
            {
                case Keys.I:
                    MessageBox.Show("CTRL+I is pressed");
                    break;

                case Keys.B:
                    MessageBox.Show("CTRL+B is pressed");
                    break;

                case Keys.L:
                    // show text
                    MessageBox.Show(((TextBoxBase)sender).Text);
                    break;
            }
        }
    }

}



// ...
// create manager that stores and manages settings for interaction areas of visual tool
TextBoxInteractionAreaAppearanceManager textBoxInteractionAreaAppearanceManager = new TextBoxInteractionAreaAppearanceManager();
// specify that manager must work with annotation visual tool
textBoxInteractionAreaAppearanceManager.VisualTool = _annotationTool;
// ...
Best regards, Alexander