How to change alignment of a report field in cryst

2019-06-28 07:31发布

问题:

In a crystal report, I want to set alignment of a fields accordingly. How can i do the same at run time?


That's nice.This is working.Thanks.I did same, and code is shown below.

var fo = rpt.ReportDefinition.ReportObjects["InvoiceComment"];
fo.ObjectFormat.HorizontalAlignment = Alignment.LeftAlign;
if (ds.Tables[0].Rows[0].ItemArray[19].ToString() == "Right")
    fo.ObjectFormat.HorizontalAlignment = Alignment.RightAlign;
else
    if (ds.Tables[0].Rows[0].ItemArray[19].ToString() == "Center")
        fo.ObjectFormat.HorizontalAlignment  = Alignment.HorizontalCenterAlign;`  

But I'm going through another problem now.

FieldObject fo = rpt.ReportDefinition.ReportObjects["InvoiceComment"] as FieldObject;                       

OR

var fo = rpt.ReportDefinition.ReportObjects["InvCom"];

Are showing same error "Index was outside the bounds of the array." And if I use Another code instead of that it works.

FieldObject fo = rpt.ReportDefinition.ReportObjects[35] as FieldObject;                                                       

How to encurr this. Thanks in Advance.

回答1:

To change the Horizontal Alignment of the field follow the below mentioned steps:

1) Right click on the field.

2) Click on Format Field Option.

3) Select the Common Tab.

4) Click the formula editor in front of Horizontal Alignment and add the setting required.

5) Following are the Alignment constants available:

Constant

crDefaultHorAligned           

crLeftAligned                 

crRightAligned                

crCenteredHorizontally        

crJustified  

use it as per your criteria.



回答2:

in C#:

var field = report.ReportDefinition.ReportObjects["Description1"];
field.ObjectFormat.HorizontalAlignment = Alignment.Justified;

possible choices:

namespace CrystalDecisions.Shared
{
    public enum Alignment
    {
        DefaultAlign,
        LeftAlign,
        HorizontalCenterAlign,
        RightAlign,
        Justified,
        Decimal,
    }
}


回答3:

I used text interpretation = RTF Text and set value in rich text format and my problem is solved... I designed better crystal report dynamically using RTF.