Search code examples
textboxtelerik-reporting

Reduce font-size based on text length


How to alter the font-size of the text in a text-box based on its character count in Telerik reporting. I did the same thing in RDLC using the below query.

=iif(len(Fields!Description.Value) > 20, "8pt", "13pt")

How to map this with Telerik reporting?


Solution

  • There are a couple of ways you can achieve this.

    Conditional Formatting Rules

    Right-click on your text-box and select Conditional Formatting... Create a new rule and set your condition like this:

    Conditional Formatting

    Then click on the style builder for this condition and make the font adjustments:

    Font

    You can add as many rules as you want.

    Here's the documentation: https://docs.telerik.com/reporting/expressions-conditional-formatting

    HTMLTextBox

    The other way to apply conditional formatting is through the use of an HTMLTextBox. There you can include html markup in the value of the box and it will be rendered (with some limitations):

     =Iif(Len(Fields.Description) > 20,
         "<span style='font-size:8px'>" + Fields.Description + "</span>",
         "<span style='font-size:12px'>" + Fields.Description + "</span>")
    

    For more information on that: https://docs.telerik.com/reporting/report-items-html-text-box