SAP Knowledge Base Article - Public

2880823 - CR for VS - Change Color API stops when carriage return is found in a .NET application

Symptom

When changing a text objects font color that has a carriage return embedded in it, in code when the color is applied the text is only altered up to the carraige return.

Note: using a SHIFT ENTER does work.

Environment

Crystal Reports Developer, for Visual Studio SP 26

Reproducing the Issue

https://answers.sap.com/questions/12945441/bug-in-reportobjectcontrollermodify.html

Code sample:

CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
rd.Load(fileName);

ISCDReportClientDocument rcd = rd.ReportClientDocument;
ReportObjects allObjects = rcd.ReportDefController.ReportObjectController.GetAllReportObjects();
foreach (ReportObject o in allObjects)
{
   if (o.Kind == CrReportObjectKindEnum.crReportObjectKindText)
   {
       ISCRTextObject to = (ISCRTextObject)o;
       to.FontColor.Color = 255;
       rcd.ReportDefController.ReportObjectController.Modify(o, to);
   }
}

Cause

That code is used to change the first line of the texts color.

To change the complete objects color use the Paragraph collection of that object. see code below:

Resolution

if (o.Kind == CrReportObjectKindEnum.crReportObjectKindText)
{
    ISCRTextObject to = (ISCRTextObject)o;
    to.FontColor.Color = 255;
    for (Int32 pgNr = 0; pgNr < to.Paragraphs.Count; pgNr++)
    {
        to.Paragraphs[pgNr].FontColor.Color = 255;
        for (Int32 pgEleNr = 0; pgEleNr < to.Paragraphs[pgNr].ParagraphElements.Count; pgEleNr++)
        {
            to.Paragraphs[pgNr].ParagraphElements[pgEleNr].FontColor.Color = 255;
        }
    }
    target.ReportDefController.ReportObjectController.Modify(o, to);
}

Keywords

crforvs, text object color, .net sdk, rcd.ReportDefController.ReportObjectController.Modify, paragraph , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio