ICSharpCode.TextEditor - KeyDown problem
Asked Answered
N

3

5

I'm trying to create an auto-complete function for the ICSharpCode.TextEditor. But the fileTabs_KeyDown doesn't recognize Enter/Backspace/Tab/...

I tried to add a new KeyEventHandler to the active editor but that doesn't call my KeyDown function.

Maybe I can request the windows messages directly but I don't know how to do this because everyone is only using e.KeyDown or e.KeyPress events.

Please help...

Nevins answered 6/9, 2009 at 19:37 Comment(3)
I solved this problem by getting KeyStatesNevins
Please provide your solution as an answer so other people will be able to find it easily if they also have this issue.Biegel
@Nevins how did you do this, can you provide an answer?Gaelan
O
8

ICSharpCode.TextEditor is a composite control. If you attach event handlers to the main text editor, you won't receive any events. You have to attach to the events on textEditor.ActiveTextAreaControl.TextArea instead.

Also, the text editor itself is already handling the events. To intercept key presses, use the special event textEditor.ActiveTextAreaControl.TextArea.KeyEventHandler.

Otti answered 9/9, 2009 at 13:45 Comment(1)
Thanks Daniel, the last couple of days you've helped me out a tonne!Jessejessee
C
0

The KeyPress, KeyDown and KeyEventHandler to not fire when hitting the Enter / Backspace / Tab Keys.
To trap these key presses, you must handle the KeyUp event.
You can then check the value of KeyEventArgs.KeyCode

Christoffer answered 28/7, 2010 at 7:16 Comment(0)
S
0

As Daniel said you use the 'ActiveTextAreaControl.TextArea' events, to capture, keys like Enter, Space, and Combinations you use code like the following where im catching a CTRL + Space combination:

public frmConexon()
    {
        InitializeComponent();
        this.txtEditor.ActiveTextAreaControl.TextArea.KeyUp += new System.Windows.Forms.KeyEventHandler(TextArea_KeyUp);
    }

    void TextArea_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Space && e.Control)
        {
            TextArea S = (TextArea)sender;
            MessageBox.Show(string.Format("CTRL + Spacio ({0})", S.Caret.ScreenPosition.ToString()));
        }
    }

In this example im even retrieving the screen coordinates of the Caret, cuz I want to show a popup window there.

Sanasanabria answered 21/5, 2013 at 20:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.