RichTextBox control not working in WinForms Net6

Posted by: kev on 19 October 2022, 2:37 pm EST

    • Post Options:
    • Link

    Posted 19 October 2022, 2:37 pm EST

    The RichTextBox control doesn’t appear to be working in WinForms app written in Net6.0. The control doesn’t render any output on the report. The same report and project written using .Net Framework 4.8 works correctly. I’ve attached a sample project that demonstrates this. On running it opens a report. The report contains a RichTextBox control and a regular Textbox control, both bound to the same field. The Textbox displays the raw RTF, but the RichTextBox remains blank

    WinFormsApp1.zip

  • Posted 19 October 2022, 2:53 pm EST

    Apologies, just noticed there’s an issue in the zipped solution. Please delete the lines referencing SectionReport1 - I was doing some tests and left this in.

    I was experimenting some more with this, and added a line to the DetailFormat event of the report to directly set the RTF value of the control. When I did this I get an error “System.NotSupportedException: No data is available for encoding 1252”. I did some research on this and saw that it might need a reference to System.Text.Encoding.CodePages. Whilst this was already in the project it was an old version. I upgraded it to 6.0.0.0. This removed the error, but I still do not get any output rendered by the control

  • Posted 20 October 2022, 5:14 am EST - Updated 15 February 2023, 10:46 am EST

    Hi Kevin,

    RichTextBox does not support the RTF file at run-time when the report’s CompatibilityMode property is set to CrossPlatform.

    You are able to see the RTF output in .Net Framework as the default CompatibilityMode is GDI however, GDI compatibility mode is not supported in .Net Core or .Net 6.

    When you create the report the CompatibilityMode is automatically set as CrossPlatform as you are using .Net 6.

    I would suggest you to use the RichTextBox.HTML property to set HTML strings as Formatted text instead of using RTF or another alternative for this is to use Page Reports or RDL Reports instead of Section Reports.

    For more information on the RichTextBox control please refer to the following page of our documentation:

    https://www.grapecity.com/activereportsnet/docs/versions/v16/online/rich-textbox.html

    Regards,

    Akshay

  • Posted 20 October 2022, 5:19 am EST

    Thanks Akshay. I had already implemented a workaround using the RtfPipe package to convert the RTF sources to HTML. I’m overwriting the bound RTF field with the HTML conversion in the section’s Format event. Not sure if I’ve checked if I can simply provide HTML instead of RTF via the bound field, as that would be cleaner

  • Posted 20 October 2022, 5:33 am EST - Updated 15 February 2023, 10:45 am EST

    Hi Kevin,

    Well, in your sample if I simply change the RTF Text with “

    <html><body>test</body></html>
    ” everything works as expected. So you don’t have to modify anything in the report.

    Here’s the modified line of code:

    data.Add(New RtfData With {.FormattedMessage = "<html><body>test</body></html>"})

    Since you are using HTML, I suppose the following documentation page would be helpful for you as well. As it mentions all the supported HTML Tags and Attributes in ActiveReports RichTextBox and FormattedText control:

    https://www.grapecity.com/activereportsnet/docs/versions/v16/online/formatted-text.html

    For reference, I have also attached the modified sample application as well.

    Regards,

    Akshay

    test.zip

  • Posted 20 October 2022, 5:36 am EST

    Thanks Akshay, that will simplify things

Need extra support?

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

Learn More

Forum Channels