SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Need an example of catching keypress events

Last post 06-16-2008 8:10 AM by punkdevil. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 01-16-2008 6:19 AM

    Need an example of catching keypress events

    help! I've googled until I can't google no more. I'm trying to use the TextEditor but can't for the life of me figure out how to catch the keypress events.  Does anyone have a code snippet to show how to send KeyPress events to an event handler routine?  Thanks.

  • 01-16-2008 6:55 AM In reply to

    • siegi44
    • Top 10 Contributor
    • Joined on 03-31-2006
    • Steyr, Austria
    • Posts 187
    • Team Members

    Re: Need an example of catching keypress events

    Hi,

    its less complicated than it seems to be, you have just to find the right location to attach your Handlers to, an example:

        public partial class MainForm : Form
        {
            public MainForm()
            {
                //
                // The InitializeComponent() call is required for Windows Forms designer support.
                //
                InitializeComponent();
                
                this.textEditorControl1.ActiveTextAreaControl.TextArea.KeyDown += new KeyEventHandler(this.TextEditor_KeyDown);
                this.textEditorControl1.ActiveTextAreaControl.TextArea.KeyUp += new KeyEventHandler(this.TextEditor_KeyUp);
                this.textEditorControl1.ActiveTextAreaControl.TextArea.KeyPress += new KeyPressEventHandler(this.TextEditor_KeyPress);
            }
           
            private void TextEditor_KeyDown(object sender, KeyEventArgs e)
            {
                System.Diagnostics.Debug.Print("KeyDown: " + e.KeyData.ToString());
            }
           
            private void TextEditor_KeyUp(object sender, KeyEventArgs e)
            {
                System.Diagnostics.Debug.Print("KeyDown: " + e.Modifiers.ToString());
            }
           
            private void TextEditor_KeyPress(object sender, KeyPressEventArgs e)
            {
                System.Diagnostics.Debug.Print("KeyDown: " + e.KeyChar.ToString());
            }
        }
     

    Siegfried Pammer
  • 01-16-2008 7:19 AM In reply to

    Re: Need an example of catching keypress events

    Thanks! That worked great! It's a shame that the exposed events in the TextEditor class don't work. Would make it a heckuva lot easier.

  • 06-13-2008 3:20 PM In reply to

    Re: Need an example of catching keypress events with SecondaryTextArea

     But if i use TextEditor.Split(), the events will only triggered if i am in the PrimaryTextArea.

    In the SecondaryTextArea i don't receive any events.

     

    What do i wrong? 

  • 06-14-2008 1:22 PM In reply to

    Re: Need an example of catching keypress events with SecondaryTextArea

    When you call Split a new TextAreaControl is created. You will need to access this new control and add event handlers as you did previously. Unfortunately it's difficult to get access to this secondary text area control. Looking at the Split method's code you'll have to derive your own version of the TextEditorControl class and do either one of the following:

    1) Override either the InitializeTextAreaControl method and add the handlers at that point.

    2) After the call to Split use the textAreaPanel object to access the secondary text area control. It should be the last control in its Controls collection.

    Option 1) is easier. 

  • 06-16-2008 8:10 AM In reply to

    Re: Need an example of catching keypress events with SecondaryTextArea

     Many Thanks!

    I derived from TextEditorControl and it functions perfect.

     

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.