Programmatically changing the caret location

SyntaxEditor for Windows Forms Forum

Posted 20 years ago by SamWare
Avatar
Is it possible to change the caret's location via code at runtime?

Also, is it possible to make the Home key move to column 1 every time it's pressed?

Comments (2)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes you can set editor.Caret.Offset to change its offset location.

And if you change the KeyActionMappings collection, you can remove the one for the Home key, develop a custom EditAction of your own and add it. The current one toggles between the first character in the display line and the first non-whitespace character in the display line when Home is pressed.


Actipro Software Support

Posted 20 years ago by SamWare
Avatar
thank you for your help! 'Caret.Offset' was probably the one property i didn't look at. ;)

to emulate the "Classic Home Key" functionality, i ended up using making my own EditAction:

    /// <summary>
    /// Move the caret to column one.
    /// </summary>
    public class MoveToFirstColumnAction : ActiproSoftware.SyntaxEditor.Actions.EditAction
    {
        /// <summary>
        /// Executes the edit action.
        /// </summary>
        /// <param name="context">An <see cref="EditActionContext"/> that holds context-related information.</param>
        public override void Execute(ActiproSoftware.SyntaxEditor.Actions.EditActionContext oContext)
        {
            oContext.Editor.Caret.Offset -= oContext.Editor.Caret.DisplayPosition.Character - 1;
        }
    }
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.