This is a migrated thread and some comments may be shown as answers.

Enter Key Behavior

4 Answers 90 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
WILLIAM
Top achievements
Rank 1
WILLIAM asked on 19 Apr 2013, 08:59 PM
I have a radrichtextbox that no matter what I do I can't get it to single space when hitting the enter key.

I'm explicitly setting the following when initializing the control, and then again on the SetupDocument event
Document.ParagraphDefaultSpacingAfter = 0;
Document.ParagraphDefaultSpacingBefore = 0;
Document.LineSpacing = 1;

Inspecting these properties afterwards shows that they are set to values above, but the enter key still does a double space.  I want enter to equal a "return" not "<p>"

???

4 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 22 Apr 2013, 04:50 PM
Hello,

The ParagraphDefaultSpacingBefore property is 0 by default and LineSpacing is responsible for the space between lines in the same paragraph, so you do not need to set them in order to achieve the wanted behavior. However, I am not sure why you are unable to change the spacing after, as putting this code:
this.editor.Document.ParagraphDefaultSpacingAfter = 0;
in the constructor of the page and in the DocumentChanged event handler results in the needed behavior on our end as you can verify from the attached picture.

On the other hand, this does not change the structure of the document and each time you press Enter, that will result in a new paragraph and not a line break (or return). What you can do in this regard is subscribe to the PreviewEditorKeyDown event of RadRichTextBox and suppress the default action like this:
void editor_PreviewEditorKeyDown(object sender, Telerik.Windows.Documents.PreviewEditorKeyEventArgs e)
{
    if(e.Key == Key.Enter)
    {
        e.SuppressDefaultAction = true;
        e.OriginalArgs.Handled = true;
        (sender as RadRichTextBox).Insert(FormattingSymbolLayoutBox.LINE_BREAK);
    }         
}

When pressing Enter, the space will be equal to the one between lines in the same paragraph and the document will not break into separate paragraphs. You can refer to the attached image for a reference.

Please not that it is not recomended to create large paragraphs in RadDocument for performance purposes.

I hope the provided information is helpful! Let us know if you have other questions.
 
Regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
WILLIAM
Top achievements
Rank 1
answered on 22 Apr 2013, 06:36 PM
Thanks Petya, I will give that a try.  

Another question I have is, Can you have more than one data provider for a RadRichTextBox?  Our challenge is that the source of the document can be plain text, or it can be html.  I'm working on trying to implement this, but you may be able to point to an article or something that shows how to do this.  I looked through the demos and the online documentation and I didn't see anything dealing with this specific issue.

Thanks again for your help!!!!
0
Iva Toteva
Telerik team
answered on 25 Apr 2013, 12:24 PM
Hi,

In general, you can have two data providers bound to RadRichTextBox, but that will create additional overhead in the case of two-way databinding. Then, on every change in the document, it would need to be exported twice.

You could try using HtmlFormatProvider and TxtFormatProvider instead of the respective DataProviders and update the strings and the document on demand. You could encapsulate this logic in a CustomDataProvider that sometimes uses HtmlFormatProvider and sometimes TxtFormatProvider.

The use of the format providers is illustrated here, while you can also download the source of the controls to see how the DataProviders have been implemented for reference.

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Alex Olenev
Top achievements
Rank 1
answered on 25 Oct 2013, 10:58 AM
That works well while editing.

But after saving text and reading it line breaks appears again.
Can you advice solution for that behaviour?
Tags
RichTextBox
Asked by
WILLIAM
Top achievements
Rank 1
Answers by
Petya
Telerik team
WILLIAM
Top achievements
Rank 1
Iva Toteva
Telerik team
Alex Olenev
Top achievements
Rank 1
Share this question
or