HowTo: Create a Custom PrintMethodAdapter to Print Ink Layers on the Microsoft.InkPicture Control
ID: W3298011
Background
PrintForm .NET does not recognize and print the default Ink layer on the Microsoft.InkPicture control, unless you are using the manual Ink layer painting mechanism illustrated in the Tablet PC SDK AutoClaims sample.
This HowTo shows you how to create a custom PrintForm IPrintMethodAdapter implementation that calls the InkPicture.Renderer.Draw method to render the Ink Strokes to the printout.
Implementation
This is a relatively simple procedure involving creating a class that derives from TMGDevelopment.Printing.PrintMethodPrint and overrides its PrintControl method to call the InkPicture.Renderer.Draw 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 PrintMethodInk.cs as follows:
public class PrintMethodInk : TMGDevelopment.Printing.PrintMethodPrint
{
protected override void InitializeKnownTypes()
{
base.AddSupportedType(typeof(Microsoft.Ink.InkPicture),
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)
{
Microsoft.Ink.InkPicture inkPicture = control as Microsoft.Ink.InkPicture;
// print the picture background using the standard PrintMethodAdapter for PictureBox
base.PrintControl(graphics, control, bounds, printFlags);
// draw the Ink layer on top
inkPicture.Renderer.Draw(graphics, inkPicture.Ink.Strokes);
}
}
2. In the form load event of your form add the following line:
this.printForm1.AddPrintMethod(new PrintMethodInk());
VB.NET Code Sample:
1. Create a new class file PrintMethodInk.vb as follows:
Public Class PrintMethodInk : Inherits TMGDevelopment.Printing.PrintMethodPrint
Protected Overrides Sub InitializeKnownTypes()
MyBase.AddSupportedType(GetType(Microsoft.Ink.InkPicture), _
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 inkPicture As Microsoft.Ink.InkPicture = CType(control, Microsoft.Ink.InkPicture)
' print the picture background using the standard PrintMethodAdapter for PictureBox
MyBase.PrintControl(graphics, control, bounds, printFlags)
' draw the Ink layer on top
inkPicture.Renderer.Draw(graphics, inkPicture.Ink.Strokes)
End Sub
End Class
2. In the form load event of your form add the following line:
Me.PrintForm1.AddPrintMethod(New PrintMethodInk)
Last updated
23-Mar-2006
|