RichTextBox like Format Code Block Preview

4 posts, 0 answers
  1. Stefania
    Stefania avatar
    123 posts
    Member since:
    May 2013

    Posted 23 Oct Link to this post

    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

  2. Polya
    Admin
    Polya avatar
    243 posts

    Posted 25 Oct Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Stefania
    Stefania avatar
    123 posts
    Member since:
    May 2013

    Posted 26 Oct in reply to Polya Link to this post

    Hi, thanks for your reply.

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

  4. Polya
    Admin
    Polya avatar
    243 posts

    Posted 31 Oct Link to this post

    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 PageMargin 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 allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top