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

Insert newline

7 Answers 182 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Flemming Rosenbrandt
Top achievements
Rank 1
Flemming Rosenbrandt asked on 16 Jun 2010, 08:46 AM
Hi

How do I insert a newline at a specific position (or the caret position)?

/Flemmig Rosenbrandt

7 Answers, 1 is accepted

Sort by
0
Mike
Telerik team
answered on 17 Jun 2010, 07:59 AM
Hello Flemmig Rosenbrandt,

You have generally two options depending on if you wish to insert a line break in a paragraph, or if you need to break a paragraph to two paragraphs. Here is example for each of the two cases that works with the RadRichTextBox Q2 Beta version:

private void btnAddLineBreak_Click(object sender, RoutedEventArgs e)
{
    this.radRtb.Document.InsertAtCaretPosition(FormattingSymbolLayoutBox.LINE_BREAK, new Span());
    this.radRtb.UpdateEditorLayout();
}
 
private void btnAddParagraph_Click(object sender, RoutedEventArgs e)
{
    this.radRtb.Document.InsertAtCaretPosition(Environment.NewLine, new Span());
    this.radRtb.UpdateEditorLayout();
}

All the best,
Mike
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Flemming Rosenbrandt
Top achievements
Rank 1
answered on 18 Jun 2010, 07:38 AM

Thanks. This was just what I needed. It looks fine in the editor.

 

But if I use the exported html as the message body in an email (using Afterlogic’s MailBee) the first newline is ok and goes to the next line – but the following ones disappear – no matter if I use the first or second solution you suggest.

 

 

In the exported html – Environment.NewLine / FormattingSymbolLayoutBox.LINE_BREAK is converted to the same html:

 

</p><p class="p_4468A9CA"><span class="s_D8D99854" /> 


 
Is it possible to achieve this instead?:

 

<p>&nbsp;</p> 

 
/Flemming Rosenbrandt

0
Alex
Telerik team
answered on 18 Jun 2010, 11:43 AM
Hello Flemming Rosenbrandt,

Thanks for reporting this issue. We will make sure it is fixed for the official release.
As a temporary workaround you can try adding single space at the end of the current paragraph when creating new one, thus assuring there are no empty paragraphs in the document. Here is an example:

private void btnAddParagraph_Click(object sender, RoutedEventArgs e)
{
    this.radRtb.Document.InsertAtCaretPosition(" " + Environment.NewLine, new Span());
    this.radRtb.UpdateEditorLayout();
}

I hope this is helpful. 

Sincerely yours,
Alex
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gauri
Top achievements
Rank 1
answered on 02 Oct 2010, 01:00 PM
Hello,
I tried

FormattingSymbolLayoutBox

 

 

.LINE_BREAK then it shows exception telling does not contain defination for LINE_BREAK. What to do?

 

 

 

 

 

0
Iva Toteva
Telerik team
answered on 04 Oct 2010, 01:53 PM
Hi Gauri,

You seem to be using an older version of RadRichTextBox. If you switch to the latest version, it should work fine. You can check your assembly references and includes to make sure you have added all of them:
  • Telerik.Windows.Controls;
  • Telerik.Windows.Documents;
  • Telerik.Windows.Controls.Input;
  • Telerik.Windows.Controls.Navigation.

Also, please note that FormattingSymbolLayoutBox is located in the Telerik.Windows.Documents.Layout namespace, so you have to add a using for that, I you haven't already done so.

Let us know if that solves the issue.

All the best,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gauri
Top achievements
Rank 1
answered on 05 Oct 2010, 12:13 PM
Hi,
Thanks for reply.
I already added mentioned assembly references.

Also,I add a using Telerik.Windows.Documents.Layout namespace. It shows SPACE_SYMBOL,ENTER_SYMBOL,SPACE_SYMBOL. But didnt have for new line. Can you please reply me back?

0
Iva Toteva
Telerik team
answered on 06 Oct 2010, 02:17 PM
Hi Gauri,

SPACE_SYMBOL, ENTER_SYMBOL and TAB_SYMBOL are the string fields of the FormattingSymbolLayoutBox class in version Q1 SP1 of the controls. They represent the symbols that mark an interval, end of a line and a tab symbol if you have enabled showing the formatting symbols.
 In version Q2 you have:
  • SPACE;
  • SPACE_SYMBOL_VISUAL;
  • TAB;
  • TAB_SYMBOL_VISUAL;
  • LINE_BREAK;
  • LINE_BREAK_VISUAL;
  • ENTER;
  • ENTER_SYMBOL_VISUAL;
  • PAGE_BREAK;
  • PAGE_BREAK_VISUAL.

The "visual" ones are what appears when enabling the option "Show formatting symbols" and the others is what you need if you want to actually insert an interval/ new line, etc.

If you are using Blend, the problem is that it might be referencing wrong DLLs versions, although you are prompting it to the right folder. Please remove all Telerik assemblies from the project, restert Blend and then add them again. Please make sure you are adding references to one and the same version of all Telerik assemblies. Let us know if the problem persists.

I have no other ideas, but I am positive that FormattingSymbolLayoutBox.LINE_BREAK works with Q2 SP1.

Regards,

Iva
the Telerik team

 

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Flemming Rosenbrandt
Top achievements
Rank 1
Answers by
Mike
Telerik team
Flemming Rosenbrandt
Top achievements
Rank 1
Alex
Telerik team
Gauri
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or