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

RichTextBox like Format Code Block Preview

3 Answers 224 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Mattia
Top achievements
Rank 2
Mattia asked on 23 Oct 2017, 12:49 PM

Hi,

How can I populate my RichTextBox like the Preview shown in the attachment (codeblock.jpg)?

 

I tried something like this:

previewTextBox.InsertCodeBlock(codeTextBox.Text, settings);

but the result is not the same (mypreview.jpg)

 

thank you

3 Answers, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 25 Oct 2017, 02:18 PM
Hello Stefania,

The InsertCodeBlock method used is a correct way to add a code block in RadRichTextBox.

If the visualized code is not formatted in the desired way, could you elaborate on how do you wish that it is displayed? Also, what CodeFormattingSettings are you using when calling the InsertCodeBlock method? 

If the CodeFormattingSettings are setup to use the appropriate language, line numbering, alternation, etc. and the result styling of the code block is not the desired one, you could implement a custom tagger that matches your specific needs. You can find more information on how to achieve this in our documentation: https://docs.telerik.com/devtools/wpf/controls/radrichtextbox/features/code-block#code-formatter. Also, you can take a look at our developer-focused example demonstrating how to add custom code formatting language: https://github.com/telerik/xaml-sdk/tree/master/RichTextBox/CustomCodeFormattingLanguage

Hope this helps.

Regards,
Polya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Mattia
Top achievements
Rank 2
answered on 26 Oct 2017, 12:38 PM

Hi, thanks for your reply.

I would like to remove the black border and expand it 100% height and width

0
Polya
Telerik team
answered on 31 Oct 2017, 12:11 PM
Hi Stefania,

The code block annotation is internally placed inside a table, which has the black table border. So in order to remove this border, we should get the parent table of our code block and set its Borders to empty borders:
// find the annotation start of the first code block.
CodeAnnotationRangeStart codeRangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType<CodeAnnotationRangeStart>().First();
Table table = codeRangeStart.GetParentOfType<Table>();           
table.Borders = new TableBorders();

Code blocks stretch by default to 100% of the width of the section they are placed in. If you are working in Paged layout mode and you wish to change the of the sections you could use the ChangeSectionActualPageMargin method: 
this.radRichTextBox.ChangeSectionActualPageMargin(new Telerik.Windows.Documents.Layout.Padding(0));

Regards,
Polya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
Mattia
Top achievements
Rank 2
Answers by
Polya
Telerik team
Mattia
Top achievements
Rank 2
Share this question
or