You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Andrew C. Dvorak edited this page Feb 27, 2014
·
6 revisions
This FAQ applies to ICSharpCode.TextEditor (the editor used in SharpDevelop 3.x), not to AvalonEdit.
Q: How can I access the currently selected text?
A: For accessing the currently selected text you can either use the simple version or the more complicated version. The more complicated version has the advantage that it can easily be expanded to multiple selections, which will be possible in future.
Simple: (assuming textEditor1 is the name of your TextEditor control):
// access the current text area.TextAreaControltextAreaControl=textEditor1.ActiveTextAreaControl;// Make sure something's selectedif(textAreaControl.SelectionManager.HasSomethingSelected){// Get the (first) selectionISelectioncurrentSelection=textAreaControl.SelectionManager.SelectionCollection[0];// get the selected text.stringselectedText=currentSelection.SelectedText;}
For more information about ISelection and SelectionManager see About selections.
Q: How can I handle KeyPress, KeyUp, KeyDown events?
A: It's less complicated than it seems to be, you have just to find the right location to attach your Handlers to, an example:
publicpartialclassMainForm:Form{publicMainForm(){//// The InitializeComponent() call is required for Windows Forms designer support.//InitializeComponent();this.textEditorControl1.ActiveTextAreaControl.TextArea.KeyDown+=newKeyEventHandler(this.TextEditor_KeyDown);this.textEditorControl1.ActiveTextAreaControl.TextArea.KeyUp+=newKeyEventHandler(this.TextEditor_KeyUp);this.textEditorControl1.ActiveTextAreaControl.TextArea.KeyPress+=newKeyPressEventHandler(this.TextEditor_KeyPress);}privatevoidTextEditor_KeyDown(objectsender,KeyEventArgse){System.Diagnostics.Debug.Print("KeyDown: "+e.KeyData.ToString());}privatevoidTextEditor_KeyUp(objectsender,KeyEventArgse){System.Diagnostics.Debug.Print("KeyDown: "+e.Modifiers.ToString());}privatevoidTextEditor_KeyPress(objectsender,KeyPressEventArgse){System.Diagnostics.Debug.Print("KeyDown: "+e.KeyChar.ToString());}}