在DevExpress XtraGrid里通过CustomeDrawFooter自定义表尾,运行时正常但预览时消失,如何解决?
XtraGrid对于通过CustomeDrawFooter自定义的footer在打印预览时时不被考虑到的,我们可通过另一种方法来实现在打印时表尾的创建与显示。
方法:可通过调用PrintableComponentLink(XtraPrinting控件)中的CreateReportFooterArea(object sender, CreateAreaEventArgs e)方法在打印预览时创建表尾。
关键代码:
private void gridView1_CustomDrawFooter (object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
{
Rectangle r = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 6);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(216, 215, 229)),r);
e.Painter.DrawCaption(e.Info, "表尾 ",new Font("宋体", 12f), Brushes.Azure, r, StringFormat.GenericDefault);
e.Handled = true;
}
private void link_CreateReportFooterArea(object sender, CreateAreaEventArgs e)
{
TextBrick tb = new TextBrick();
tb.Sides = BorderSide.None;
tb.Rect = new RectangleF(0, 1, e.Graph.ClientPageSize.Width, 16);
tb.Text = "表尾";
StringFormat sFormat = new StringFormat(StringFormatFlags.DirectionVertical);
sFormat.LineAlignment = StringAlignment.Near;
BrickStringFormat brickSFormat = new BrickStringFormat(sFormat);
tb.StringFormat = brickSFormat;
e.Graph.DrawBrick(tb, tb.Rect);
}
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/133.html