如何在运行时更改Crystal报表中的报表字段的对齐方式 [英] How to change alignment of a report field in crystal reoport at runtime

查看:314
本文介绍了如何在运行时更改Crystal报表中的报表字段的对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在水晶报表中,我想相应地设置字段的对齐方式。我如何在运行时也这样做?






这很好。这是工作。代码如下所示。

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

但我现在遇到另一个问题。

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

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

显示相同的错误索引超出数组的边界。
如果我使用另一个代码,而不是它的工作原理。

  FieldObject fo = rpt.ReportDefinition.ReportObjects [35] 

如何进行此操作。

要更改字段的水平对齐,请按照以下步骤操作:



1)右键单击字段。



2)单击格式字段选项。



3)选择公共选项卡。



4)单击水平对齐前的公式编辑器,然后添加所需的设置。 >

5)以下是可用的对齐常量:



常量



  crDefaultHorAligned 

crLeftAligned

crRightAligned

crCenteredHorizo​​ntally

crJustified

按照您的标准使用它。


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.

解决方案

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.

这篇关于如何在运行时更改Crystal报表中的报表字段的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆