Enter (new line)

4 posts, 1 answers
  1. Frank Beerens
    Frank Beerens avatar
    26 posts
    Member since:
    Jan 2010

    Posted 12 Dec 2013 Link to this post

    Hi,

    When I hit enter in the richtextbox, an empty line appears between the previous and the new line (like a new paragraph).
    I would like to insert a 'normal' enter/new line when I hit enter.

    Is this possible? Now the only way I can achieve this is when I hit shift + enter.

    Best regards.
  2. Frank Beerens
    Frank Beerens avatar
    26 posts
    Member since:
    Jan 2010

    Posted 17 Dec 2013 Link to this post

    Anyone???
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 17 Dec 2013 Link to this post

    Hi Frank,

    Thank you for writing.

    In order to change the input behavior of the control, you should create a descendant of the InputBehavior class and override the desired method. Here is how to change the Enter key behavior as per your request:
    class MyInputBehavior : InputBehavior
    {
     
        public MyInputBehavior(DocumentView view)
            : base(view)
        {
     
        }
     
        protected override bool ProcessEnterKey(KeyEventArgs e)
        {
            e.SuppressKeyPress = true;
            this.DocumentView.Insert(FormattingSymbolLayoutBox.LINE_BREAK);
            return true;
        }
    }

    And here is how to put this behavior in action:
    radRichTextBox1.DocumentView.InputBehavior = new MyInputBehavior(radRichTextBox1.DocumentView);

    I hope this helps.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Frank Beerens
    Frank Beerens avatar
    26 posts
    Member since:
    Jan 2010

    Posted 18 Dec 2013 Link to this post

    Thank you, that did the job!
Back to Top