Pergunta

I want to create my own custom graphic based on some parameterized data and have it be generated in a subreport. I placed a ActiveReports.Picture element on the report. I then drew my image in memory using the System.Drawing.Graphics object and then set it to the Image property of the Picture control. This works OK, but the image on the generated PDF is blurry, even after setting the pdfExport1.ImageQuality to highest.

I think it would be better to draw directly on to the ActiveReports Document canvas, but I can't figure out how to make that work. All the examples out there point you to the same basic example:

http://www.datadynamics.com/Help/ActiveReports6/topic2107.html

The problem is that the example is out of context. I don't see where this code should run? Inside the sub-report? In the calling report? Outsize the report entirely? When I tried it in the report, the Pages property had no pages (got an index out of bounds error), so I may be doing it in the wrong event.

To be clear, this is not a data-driven report. I get all the data I need via parameters. No DB access is required.

Thanks.

Foi útil?

Solução

In the examples in the documentation you referenced, the DrawLine is drawing on the parent document/report (not the subreport). You can however draw on a page as a section is processed. To do that, you put your rendering code inside of the processing events of the section such as BeforePrint event or AfterPrint event (I would avoid using the Format as there are many caveats when using Format).

To draw on the page from within a section's event, you can find the location of the section from the Section class' CurrentLocation property. For example, to draw a diagonal line across the entire section from the BeforePrint event you could use the following code:

public void Detail_BeforePrint(object sender, System.EventArgs eArgs)
{
    this.CurrentPage.BackColor = System.Drawing.Color.Purple;
    this.CurrentPage.ForeColor = System.Drawing.Color.YellowGreen;
    this.CurrentPage.PenStyle = DataDynamics.ActiveReports.Document.PenStyles.Dot;
    this.CurrentPage.PenWidth = 4;
    this.CurrentPage.DrawLine(Detail.CurrentLocation.X, Detail.CurrentLocation.Y, this.PrintWidth, Detail.Height);
}

This code should work fine within a subreport or a parent report. Apparently you will need to change this.CurrentPage to ParentReport.CurrentPage if you want to draw on the page from within a subreport. If you want to draw relative to the page, you can use similar code but use the PageEnd event. There is a good example in the PageEnd Event's documentation. However, the PageEvents will only work for the parent report, it may be difficult to orient the drawing coordinates relative to a subreport's location.

Outras dicas

It seems you have to draw on the main page, even from the subreport, which is why CurrentPage is null. So the following from the subreport works:

this.ParentReport.CurrentPage

http://www.datadynamics.com/forums/118838/ShowPost.aspx

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top