XtraReport交叉表自适应行高及最佳列宽(转)
XtraReport交叉表自適應行高及最佳列寬
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官方的一張效果圖:
轉載于:https://www.cnblogs.com/ThreeGrowthPlan/p/9391505.html
總結
以上是生活随笔為你收集整理的XtraReport交叉表自适应行高及最佳列宽(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CPU GPU FPU TPU 及厂商
- 下一篇: Apollo 8 — ConfigSer