Change color or font of a part of the text in Flexreport

Posted by: saidnai on 14 January 2024, 10:34 pm EST

    • Post Options:
    • Link

    Posted 14 January 2024, 10:34 pm EST

    Hi,

    is there away to change the font or color in one text field in the C1Flexreport before viewing/printing?

    For example: Text in the report = “Life is good”

    “Life” should have the font and color different to “is good”.

    Best regards

    Said

  • Posted 15 January 2024, 8:56 pm EST - Updated 15 January 2024, 9:01 pm EST

    Hi Said,

    I think you would have to use RTF formatted text in the report field and set the field property “RTF” to true:

    Best regards

    Wolfgang

  • Posted 15 January 2024, 11:04 pm EST - Updated 15 January 2024, 11:10 pm EST

    Hi Said,

    Apologize, the Formatted text is not supported in a normal TextField. To achieve your requirement, you need to use RTFField.

    Please refer the attached FlexReport sample: RtfField.zip

    If you are working with legacy Fields then you can follow Wolfgang’s solution.

    And thanks Wolfgang for the guidance.

    Regards,

    Nitin

  • Posted 16 January 2024, 2:17 am EST

    Dear Nitin,

    I do not use the legacy fields and i cannot see the option “Special” in my FlexReportDesigner.

    It is good to know that is possible. I will explain my problem as follow:

    The value of the Text is from a table. Before printing/viewing I need to check the value for a specific word like “Block no 111” and assign to it the red color.

    Best regards also thanks Wolfgang for your support.

    Said

  • Posted 16 January 2024, 3:04 am EST - Updated 16 January 2024, 3:09 am EST

    Hi Said,

    you are right, my screenshot was from an old legacy report.

    But you can insert “RTF fields”:



    I hope that you can use them in unbound mode and just assign the RTF text to the “Text” property.

    Best regards

    Wolfgang

  • Posted 16 January 2024, 9:24 pm EST

    Hi Said,

    If you are not using the legacy Fields. Then you need to use RtfField as suggested by Wolfgang.

    And then you can set the unbound formatted data in it.

    Regards,

    Nitin

  • Posted 16 January 2024, 10:53 pm EST

    Hi Nitin,

    can you please provide a VB sample to work around?

    Best regards

    Said

  • Posted 17 January 2024, 8:25 pm EST

    Hi Said,

    You can update the RtfField at the time of previewing the Detail Section. You can add a script under Details.OnFormat to update the RtfField accordingly.

    Please refer the attached VB sample for the same: FlexReportSample.zip

    Best Regards,

    Nitin

  • Posted 18 January 2024, 7:36 pm EST - Updated 18 January 2024, 7:41 pm EST

    Hi Nitin,

    As you can see in the picture. i can print the text between brakets in Red. The problem also as you can is the font, the allignement and the space an the beginning end between the black text and the red text. I do not know where it comes from.

    with RTF Field is my first experience :slight_smile:

    hier is the code i use under Details.OnFormat:

    'Define the braket start/end

    VInStart = Instr(fldRohstoff.Text, “(”)

    VInEnde = Instr(fldRohstoff.Text, “)”)

    If VInStart > 0 Then

    'Red Color

    Value1 = Mid(fldRohstoff.Text, 1, VInStart - 2)

    Value2 = Mid(fldRohstoff.Text, VInStart - 1, VInEnde - 1)

    fldRohstoff.Text = “{\rtf1

    {\fonttbl

    {\f0\fcharset1 Arial; }

    }

    {\colortbl;\black;\red255\green0\blue0; }

    \cf1 \pard \fs30 \b “&[Value1]&”

    {\fonttbl

    {\f0\fcharset1 Arial;\b bold\b0; }} \cf2 \fs30 \b “&[Value2]&”}”

    Else

    'all in black

    EndIf

    Best regards

    Said

  • Posted 18 January 2024, 7:41 pm EST

    Hi Said,

    maybe too many spaces in the string " \cf2 \fs30 \b "?

    Best regards

    Wolfgang

  • Posted 18 January 2024, 7:58 pm EST

    Hi Wolfgang,

    Thanks for the quick reply.

    The string contains only the following:

    “R Titan LG Grün (Sperr-Nr.:235)”

    Best regards

    Said

  • Posted 18 January 2024, 8:01 pm EST

    Yes, but maybe the rtf renderer also renders the spaces between the formatting tags.

    Could you change it to "\cf2\fs30\b "?

    Best regards

    Wolfgang

  • Posted 18 January 2024, 8:15 pm EST - Updated 18 January 2024, 8:20 pm EST

    Hi Wolfgang,

    You are right. It should be like follow:

    Value1 = Mid(fldRohstoff.Text, 1, VInStart - 2)

    Value2 = Mid(fldRohstoff.Text, VInStart - 1, VInEnde - 1)

    fldRohstoff.Text =“{\rtf1{\fonttbl{\f0\fcharset1 Arial;}}{\colortbl;\black;\red255\green0\blue0;}\cf1\fs30\b”&[Value1]&“{\fonttbl{\f0\fcharset1 Arial;\b bold\b0;}}\cf2\fs30\b”&[Value2]&“}”

    See attached picture.

    By the way how about the allignement?

    Best regards

    Said

  • Posted 18 January 2024, 11:13 pm EST

    Hi Said,

    We are happy that the issue is solved at your end.

    And thanks Wolfgang for looking out into this.

    Regards,

    Nitin

  • Posted 18 January 2024, 11:19 pm EST

    Hi Nitin,

    i still have the issue with the Vertical alignement. If you can help.

    I found the following : \vertalc and still look where to place to get it work.

    as you can see in the picture, it is not correctly alligned.

    Thank you

    Said

  • Posted 18 January 2024, 11:32 pm EST

    Sorry, this is far off my own experience with C1FlexReport, so I cannot help you further - it is up to C1 support to provide further help :-(.

    The RtfField has a property “Alignment”, but the description says that it is supported only if the rtf content is not enclosed with “\rtf1”. And I did not find a rtf specification which describes alignment.

    You could try to assign your RTF string to a WinForms “RichTextBox” control. I assume that C1FlexReport uses this control internally to render the string. So, if your text looks as expected in the WinForms control, it should work in C1FlexReport, too.

    Best regards

    Wolfgang

  • Posted 18 January 2024, 11:50 pm EST - Updated 18 January 2024, 11:56 pm EST

    Hi Wolfgang,

    Thanks a lot for your support.

    The attached picture before as a result is from C1Flexreport.

    The properties of an RTF in the C1Flexreport are the following see actual picture. I guess you have the same.

    Best regards

    Said

  • Posted 19 January 2024, 12:40 am EST

    Hi Said,

    For the VerticalAlignment you can set \sbN(where N is a number in Twips) to align and spacing on top of the text. You can refer to this article for the same: https://www.oreilly.com/library/view/rtf-pocket-guide/9781449302047/ch01.html

    We have updated our sample. To achieve vertical Alignment space within Rtf text. Please refer the attached modified sample for the same: FlexReportSample_Mod.zip

    Best Regards,

    Nitin

  • Posted 22 January 2024, 12:26 am EST - Updated 22 January 2024, 12:31 am EST

    Hi Nitin,

    It works now.

    Best regards

    Said

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels