Hi,
I am reading an RTF string from a database and displaying it in a radRichTextEditor. Many of these are multi-line instructions, including many bullet point lists. In order to format this more nicely I wrote the following snippet
private void ConfigureDocumentEditor(RadRichTextEditor editor)
{
var docEditor = new Telerik.WinForms.Documents.Model.RadDocumentEditor(editor.Document);
editor.Document.Selection.SelectAll();
docEditor.ChangeFontSize(8);
docEditor.ChangeParagraphLineSpacing(0.25);
editor.Document.Selection.Clear();
editor.IsReadOnly = true;
}
I also set the LayoutMode to "Flow". The problem that I'm running into is that in some instances the data in the DB is just one long string. When I set ChangeParagraphLineSpacing to a value >= 1.0 the word wrap works nicely. When ChangeParagraphLineSpacing < 1.0 it looks like the attached image. Is there any way to change the spacing so that it applies to paragraph breaks and lists but not the line spacing caused by word wrapping?
Thanks
5 Answers, 1 is accepted
Hi Shawn,
The value applied for the line spacing is pretty small and causes the lines to appear one on the top of the other. Can you please share more details on why you need to apply such a small value and what is the end goal you need to achieve? I am trying to get a better understanding of the case so I can suggest you the most appropriate approach for achieving the desired result.
Looking forward to hearing from you.
Regards,
Tanya
Progress Telerik
Hi Tanya,
Thank you for getting back to me on this. I'm uploading 2 images which I think demonstrate the use case fairly well.
I have a text field (RichTextEditor) with limited real estate. While there are exceptions, a typical item that gets displayed here is of this format:
Opening paragraph (often Very long)
* bulleted list of actions
* second action
* final action
Closing paragraph.
In BigBullets.png you see that I can fit most of this on the screen, but not the closing paragraph.The items are spaced out greatly with a lot of white space -- "docEditor.ChangeParagraphLineSpacing(1.0)"
In SmallBulletSpacing.png, you can see that I save a lot of real estate when the items are closer together "docEditor.ChangeParagraphLineSpacing(0.25)". However the paragraphs become unreadable because the word wrap is ruined.
Hopefully this explains what I'm trying to accomplish. Thanks for your help.
Hello Shawn,
As far as I understand, you need to minimize the space between the lines and ensure the whole space of the line is exactly as big as needed to accommodate the text. If this is correct, you can set the line spacing to 1 and remove the spacing after the paragraphs:
var docEditor = new Telerik.WinForms.Documents.Model.RadDocumentEditor(editor.Document);
editor.Document.Selection.SelectAll();
docEditor.ChangeFontSize(8);
docEditor.ChangeParagraphLineSpacing(1);
docEditor.ChangeParagraphSpacingAfter(0);
editor.Document.Selection.Clear();
editor.IsReadOnly = true;
Hope this suggestion fits your needs.
Regards,
Tanya
Progress Telerik
Thanks Tanya!
That's exactly the method I was looking for. For clarity, is the value accepted by those methods in pixels, is it a percentage of font size or something else?
Hello Shawn,
The value of the Line spacing is a bit complex. For example, ChangeParagraphLineSpacing(1) is equal to setting Single line spacing through the UI. The Single preset depends on the font size and the currently selected font. Basically, it is somewhere between 110% and 135% of the current font size. You can find additional information on line spacing in this article (it's for MS Word but it is still relevant).
As for the paragraph spacing it is measured in DIP (Device Independent Pixels). In order to set the value in points (pt), you will need to convert it using PointToDip method from the Unit class.
I hope you find this information sufficient.
Regards,
Vladislav
Progress Telerik