PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
IntegraMike
Posts: 56
Joined: Mon Dec 02, 2019 11:19 pm

PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Post 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
Alex
Site Admin
Posts: 2307
Joined: Thu Jul 10, 2008 2:21 pm

Re: PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Post by Alex »

Hello Mike,

Do you use WinForms or WPF?

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Post by IntegraHarlan »

Hi Alexander,
We are using WinForms

Thanks
Alex
Site Admin
Posts: 2307
Joined: Thu Jul 10, 2008 2:21 pm

Re: PdfFreeTextAnnotation Edit Mode Capturing Keyboard Events

Post 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
Post Reply