码迷,mamicode.com
首页 > 其他好文 > 详细

XtraReport交叉表自适应行高及最佳列宽(转)

时间:2018-07-30 17:14:42      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:str   add   事件   owa   i++   es2015   port   appear   play   

1.自适应行头的行高,绑定CustomRowHeight事件,代码如下:

private Graphics gr = Graphics.FromHwnd(IntPtr.Zero);

private void pivotGrid1_CustomRowHeight(object sender, HuanSi.XtraReports.UI.PivotGrid.PivotCustomRowHeightEventArgs e) {

e.RowHeight = 20;

var grid=sender as HuanSi.XtraReports.UI.XRPivotGrid;

var list=e.Data.GetFieldsByArea(HuanSi.XtraPivotGrid.PivotArea.RowArea, false);

foreach (var item in list)

{

        var obj=grid.GetFieldValue(item, e.RowIndex);

        if (obj == null)

        continue;

        var font = (item as HuanSi.XtraReports.UI.PivotGrid.XRPivotGridField).Appearance.Cell.Font;

        SizeF size = gr.MeasureString(obj.ToString(), font, item.Width);

        int height = Convert.ToInt32(Math.Ceiling(size.Height));

        e.RowHeight = e.RowHeight > height ? e.RowHeight : height;

}

}

效果图如下:

技术分享图片

2.自适应数据的行高,同样绑定CustomRowHeight事件,代码如下:

private Graphics gr = Graphics.FromHwnd(IntPtr.Zero);

private void xrPivotGrid1_CustomRowHeight_1(object sender, PivotCustomRowHeightEventArgs e) {

e.RowHeight = 0;

for (int i = 0; i <= e.ColumnCount - 1; i++) {

string value = e.GetRowCellValue(i).ToString();

SizeF size = gr.MeasureString(value, e.DataField.Appearance.Cell.Font, e.DataField.Width);

int height = Convert.ToInt32(Math.Ceiling(size.Height));

e.RowHeight = e.RowHeight > height ? e.RowHeight : height;

}

}

盗用网上一张效果图:

技术分享图片

3.自适应列宽

自适应列宽则极其简单,绑定BeforePrint事件即可,代码如下:

private void pivotGrid1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {

var grid=sender as HuanSi.XtraReports.UI.XRPivotGrid;

grid.BestFit();

}

再次盗用DX官方的一张效果图:

技术分享图片

XtraReport交叉表自适应行高及最佳列宽(转)

标签:str   add   事件   owa   i++   es2015   port   appear   play   

原文地址:https://www.cnblogs.com/ThreeGrowthPlan/p/9391505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!