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: Eliminate 'White Blocks' when Printing a Custom or Third Party Control in PrintForm.NET

ID: W32980012

 

Background

When PrintForm.NET encounters a control is doesn't know how to print it shows the error 'Error 0x0001. No PrintMethod available.' on the printout. (Note: these messages may not be shown on the printout if you have set PrintForm.ShowUnsupportedControlsOnPrintout = false).

If you have followed the instructions in document W32980003 - HowTo: Assign a PrintMethodAdapter to a Control in PrintForm.NET you may find that controls contained within the control are printed as white rectangles when they shouldn't be visible at all. This is a result of the PrintForm feature that separates printing visibility from on screen visibility, allowing you to print controls that are not visible, or conversely not print controls that are visible.

This HowTo shows you how to tell PrintForm not to print hidden controls contained within your target control.

Setting the Visibility of Contained Controls

In this example, as in W32980003 - HowTo: Assign a PrintMethodAdapter to a Control in PrintForm.NET, we retrieve the most commonly used PrintForm IPrintMethodAdapter implementation, PrintMethodPrint, and associate it this time with the type Syncfusion.Windows.Forms.Grid.GridControl, part of the Syncfusion control library. Note: in your code you would replace the Syncfusion.Windows.Forms.Grid.GridControl with the Type you wish to associate with the given PrintMethodAdapter. Typically you would execute this code in the Form Load event handler, or in the constructor after InitializeComponent has been called.

Then at print time we set the PrintForm visibility of contained controls to match the onscreen visibility in the PrintForm BeginPrint event handler using a recursive utility function UpdateVisibleWhilePrinting, that calls PrintForm SetVisibleWhilePrinting .

C# Code Sample:

place this code in Form Load event, and remember to wire up the printForm1_BeginPrint event handler below

// retrieve the existing PrintMethodAdapter from PrintForm's internal collection:
TMGDevelopment.Printing.IPrintMethodAdapter pma = this.printForm1.GetPrintMethod(typeof(TMGDevelopment.Printing.PrintMethodPrint));
// add an extra supported type to the PrintMethodAdapter:
pma.AddSupportedType(typeof(Infragistics.Win.UltraControlBase));


place this code in the main body of the Form implementation

private void UpdateVisibleWhilePrinting(TMGDevelopment.Windows.Forms.PrintForm printForm, Control parent)
{
  foreach (Control c in parent.Controls)
  {
    printForm.SetVisibleWhilePrinting(c, c.Visible);
    UpdateVisibleWhilePrinting(printForm, c);
  }
}

private void printForm1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
  UpdateVisibleWhilePrinting(this.printForm1, this.gridControl1);
}

VB.NET Code Sample:

place this code in Form Load event

' retrieve the existing PrintMethodAdapter from PrintForm's internal collection:
Dim pma As TMGDevelopment.Printing.IPrintMethodAdapter = Me.PrintForm1.GetPrintMethod(GetType(TMGDevelopment.Printing.PrintMethodPrint))
' add an extra supported type to the PrintMethodAdapter:
pma.AddSupportedType(GetType(Infragistics.Win.UltraControlBase))

place this code in the main body of the Form implementation

Private Sub printForm1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintForm1.BeginPrint
  UpdateVisibleWhilePrinting(Me.PrintForm1, Me.gridControl1)
End Sub

Private Sub UpdateVisibleWhilePrinting(ByVal printForm As TMGDevelopment.Windows.Forms.PrintForm, ByVal parent As Control)
  Dim c As Control
  For Each c In parent.Controls
    printForm.SetVisibleWhilePrinting(c, c.Visible)
    UpdateVisibleWhilePrinting(printForm, c)
  Next
End Sub

Last updated 04-Apr-2019