Winform Reports for .NET
   Home
   Product Comparison
   Products
     PrintForm .NET
     PrintControls .NET
     PrintAdapters .NET
     PrintPreviewDialog .NET
     Localizer ASP.NET
     WebExtenders ASP.NET
   Downloads
     Free Trial Versions
     Upgrades
   Documents & Papers
   Purchase
   Support Index
   Press Releases
   Contact Us
   Privacy Statement
 
 
 
Go to TMG Development Ltd Website
Microsoft Certified Partner

HowTo: Create a Custom PrintMethodAdapter for the SoftwareFx.ChartFx.Chart Control

ID: W3298010

 

Background

The SoftwareFX.ChartFX.Chart control (see www.softwarefx.co.uk) does not print correctly using the PrintForm technique described in W3298003 (HowTo: Assign a PrintMethodAdapter to a Control in PrintForm.NET) due to nested controls that are internal to the ChartFx assembly.

This HowTo shows you how to create a custom PrintForm IPrintMethodAdapter implementation that calls the ChartFx.Paint method to render the chart into the printout.

Implementation

This is a relatively simple procedure involving creating a class that derives from TMGDevelopment.Printing.PrintMethodbase and overrides its PrintControl method to call the ChartFx Paint method at the appropriate time. At runtime this new IPrintMethodAdapter implementation is added to the PrintForm collection via a call to PrintForm.AddPrintMethod.

C# Code Sample:

1. Create a new C# class file PrintMethodChartFx.cs as follows:

public class PrintMethodChartFx : TMGDevelopment.Printing.PrintMethodBase
{
  protected override void InitializeKnownTypes()
  {
    base.AddSupportedType(typeof(SoftwareFX.ChartFX.Chart),
      TMGDevelopment.Printing.PrintMethodOptions.CanPrintVisualStyle |
      TMGDevelopment.Printing.PrintMethodOptions.CanPrintNonVisualStyle |
      TMGDevelopment.Printing.PrintMethodOptions.RequiresPrintChildren);
  }

  public override void PrintControl(System.Drawing.Graphics graphics, System.Windows.Forms.Control control, System.Drawing.Rectangle bounds, TMGDevelopment.Printing.PrintFlags printFlags)
  {
    SoftwareFX.ChartFX.Chart chart = control as SoftwareFX.ChartFX.Chart;
    // Note: remove the SoftwareFX.ChartFX.PaintFlags.Border flag if you don't want the chart border
    chart.Paint(graphics, bounds, SoftwareFX.ChartFX.PaintFlags.Metafile | SoftwareFX.ChartFX.PaintFlags.Border);
  }
}

2. In the form load event of your form add the following line:

this.printForm1.AddPrintMethod(new PrintMethodChartFx());

 

VB.NET Code Sample:

1. Create a new class file PrintMethodChartFx.vb as follows:

Public Class PrintMethodChartFx : Inherits TMGDevelopment.Printing.PrintMethodBase

Protected Overrides Sub InitializeKnownTypes()
  MyBase.AddSupportedType(GetType(SoftwareFX.ChartFX.Chart), _
    TMGDevelopment.Printing.PrintMethodOptions.CanPrintVisualStyle Or _
    TMGDevelopment.Printing.PrintMethodOptions.CanPrintNonVisualStyle Or _
    TMGDevelopment.Printing.PrintMethodOptions.RequiresPrintChildren)
End Sub

Public Overrides Sub PrintControl(ByVal graphics As System.Drawing.Graphics, ByVal control As System.Windows.Forms.Control, ByVal bounds As System.Drawing.Rectangle, ByVal printFlags As TMGDevelopment.Printing.PrintFlags)
  Dim chart As SoftwareFX.ChartFX.Chart = CType(control, SoftwareFX.ChartFX.Chart)
  ' Note: remove the SoftwareFX.ChartFX.PaintFlags.Border flag if you don't want the chart border
  chart.Paint(graphics, bounds, SoftwareFX.ChartFX.PaintFlags.Metafile Or SoftwareFX.ChartFX.PaintFlags.Border)
End Sub

End Class

2. In the form load event of your form add the following line:

Me.PrintForm1.AddPrintMethod(New PrintMethodChartFx)


Last updated 23-Mar-2019