【发布时间】:2015-12-01 16:30:23
【问题描述】:
因此,在我们的报告中,我们在 Detail Band 中有一个 ImageBox,我们希望每页都有不同的图像。
看到在 Detail Band 的 BeforePrint 事件中更改它不起作用(因为每次打印报告只调用一次)我遵循以下方法到目前为止(不起作用):
在报告的页眉带标签的 PrintOnPage 事件中(为了将其称为 per page 并能够在新的 XRPictureBox 中使用 PrintOnPageEventArgs - 我需要 PageIndex ):
private void xrLabel10_PrintOnPage(object sender, PrintOnPageEventArgs e)
{
this.Detail.Controls.Remove(xrPictureBox1); //Existing PictureBox control
this.Detail.Controls.Add(PictureBox(e));
}
这叫:
private List<Bitmap> _imageList;
public XRPictureBox PictureBox(PrintOnPageEventArgs e)
{
XRPictureBox pictureBox = new XRPictureBox();
var articleService = DependencyResolver.Current.GetService<IArticleService>();
int width;
int height;
pictureBox.Name = "xrPictureBox_" + e.PageIndex;
pictureBox.BackColor = Color.Transparent;
pictureBox.Dpi = 254F;
pictureBox.LocationFloat = new DevExpress.Utils.PointFloat(108.4792F, 71.4375F);
pictureBox.Name = "xrPictureBox_" + e.PageIndex;
pictureBox.SizeF = new SizeF(950F, 1225F);
pictureBox.Sizing = ImageSizeMode.Squeeze;
pictureBox.StylePriority.UseBackColor = false;
if (ReportUnit == ReportUnit.HundredthsOfAnInch)
{
width = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Width, GraphicsUnit.Inch, GraphicsUnit.Pixel) / 100);
height = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Height, GraphicsUnit.Inch, GraphicsUnit.Pixel) / 100);
}
else
{
width = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Width, GraphicsUnit.Millimeter, GraphicsUnit.Pixel) / 10);
height = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Height, GraphicsUnit.Millimeter, GraphicsUnit.Pixel) / 10);
}
if (_imageList == null)
{
_imageList = articleService .GetListOfImages((int)articleId.Value, width, height, PageColor); //this gets a List<Bitmap>
}
if (_imageList[e.PageIndex] == null)
return null;
pictureBox.Image = _imageList[e.PageIndex];
return pictureBox;
}
所以基本上我的想法是用新的 XRPictureBox 替换现有的 Control 和新的图像。但它只是没有出现在报告中,即使在调试时我看到代码正在运行并为正确的页面检索正确的图像。
编辑:nempoBu4 的回答通常是正确的,但不幸的是,我未能澄清一个额外的问题,这使得它不适合我的情况: 该报表在 PictureBox 旁边还有一个子报表,该子报表可以扩展到多个页面。我们希望 PictureBox 在每个页面中呈现不同的图像,并且它们不会触发 PictureBox 的 PrintOnPage 事件。我会尽快用我们找到的解决方法添加答案:)
【问题讨论】:
标签: c# asp.net devexpress xtrareport