CLR Extender Reference

Printing Sample

Description »

This is a sample in construction it forms the basis of the next generation Object Oriented Report system in development for the .NET Compiler for VFP. In the next OOP Report you will design your reports using the Form Designer and then the output will be produced using the .NET Framework.

Here is the Form Designer with the sample provided:

And here is the same form running in Preview Mode (by clicking the Preview Button).

The sample uses several controls from the library reporting.vcx stored in HOME()+"Tools\eTecnologiaNETExtender\Samples\Printing\Libs".

Each control supports Background and Foreground brushes then in addition to the SolidColor of VFP also sports Gradient and Textured Brushes and any other Brush available in the .NET Framework. The brushes are initialised in the InitBrush method of every control. The properties nBackgroundFillStyle and nForegroundFillStyle determines what kind of brush to create in InitBackgroundBrush and InitForegroundBrush, both methods call InitBrush.

Also each control supports Pen Functionality which determines what kind of Pen to use for drawing lines - see the method InitPen.

The Drawing functionality is in the method GenerateOutput that receives two parameters toPageInfo and toPrintInfo.

See this method in the following classes.

  • Reportlabel (baseclass = Label) shows how to Draw String using System::Drawing::Graphics::DrawString.
  • ReportImage (BaseClass = Image) shows you how to draw images stored in files.
  • ReportTextBox illustrates drawing Text from TextBoxes it is similar to ReportLabel.
  • ReportBand (BaseClas = Container) shows how to iterate through the Contained VFP Controls calling each control GenerateOutput.
  • BaseReportForm (BaseClass = Form), is a typical Foxpro Form with bands on it. Its GenerateOutput create a System::Windows::Forms::PrintPreviewDialog that provides the Preview Functionality, CLRBindEvent the System::Drawing::Printing::PrintDocument::PrintPage event in THIS.oPrintDocument to the form's method PrintPageHandler .
    LOCAL i
    THIS.BeforeGenerateOutput()
    DO CASE
    CASE THIS.nOutputtype = 1
    LOCAL oDialog
    oDialog = CLRCreateObject("system::windows::forms::PrintPreviewDialog")
    oDialog.Document = THIS.oPrintdocument
    = CLRBindEvent(THIS.oPrintdocument,"PrintPage",THIS,"PrintPageHandler",.T.)
    oDialog.Show()
    CASE THIS.nOutputtype = 0
    = CLRBindEvent(THIS.oPrintdocument,"PrintPage",THIS,"PrintPageHandler",.T.)
    THIS.oPrintdocument.Print()

    ENDCASE
    THIS.AfterGenerateOutput()

In PrintPageHandler the form outputs the Header (method OutputElement), goes through each record and outputs the details if there is enough room on it and then prints the footer.

PROCEDURE PrintPageHandler
LPARAMETERS m.toSource, m.toPrintPage
LOCAL cAlias, nHeightPrinted
cAlias = ALIAS()
THIS.nCurrentPrintedHeight = 0
THIS.oPrintSource = m.toSource
THIS.oPrintPage = m.toPrintPage
THIS.BeforePage()
THIS.oPrintpage.Graphics.TranslateTransform(0,-50)
THIS.OutputElement(THIS.oHeaderBand)
SCAN REST
THIS.oPrintPage.Graphics.ResetTransform()
THIS.oPrintpage.Graphics.TranslateTransform(0,THIS.ncurrentprintedheight)
IF THIS.oDetailBand.Printwhen()
IF THIS.oDetailBand.Height + THIS.oFooterBand.Height >= m.toPrintPage.PageBounds.Height - THIS.nCurrentprintedheight
EXIT
ENDIF
THIS.Outputelement(THIS.oDetailBand)
ENDIF
ENDSCAN
THIS.oPrintPage.Graphics.ResetTransform()
THIS.oPrintpage.Graphics.TranslateTransform(0,THIS.ncurrentprintedheight)
THIS.Outputelement(THIS.oFooterBand)
Example »

Remarks »

The power of this sample lies in the fact you can use all the Object Oriented Features of VFP, because you design a form and then place your controls on it. Of course you can create your own controls and override their GenerateOutput method to Draw anything you want.

This sample is just that, a Sample and a Proof of Concept. It will keep evolving so check www.eTecnologia.net for further improvements.

As already mentioned, this will be the Technology used for the next Object Oriented Report.

This next generation Report Technology will preserve any Report Investment you have already done because it will convert your FRX reports to Forms Reports, additionally it allows you to output using any ReportListener you have created.

Two output formats already implemented but not showed in the sample are PDF (Portable Document Format) and SVG (Scalable Vector Graphics). Additionally there could be a third format: SWF (Flash format).

Naturally with Windows Vista will come XPS, and you'll be able to consume any report listener that outputs to that format.

Other Resources »

.NET Compiler for VFP


Send comments about this topic to eTecnologia.net.