Leadtools.Windows.Printing Namespace > PrinterHelper Class : CreateCanvas Method |
public virtual Canvas CreateCanvas( UIElement element, PrintPageEventArgs args )
'Declaration Public Overridable Function CreateCanvas( _ ByVal element As UIElement, _ ByVal args As PrintPageEventArgs _ ) As Canvas
'Usage Dim instance As PrinterHelper Dim element As UIElement Dim args As PrintPageEventArgs Dim value As Canvas value = instance.CreateCanvas(element, args)
public virtual Canvas CreateCanvas( UIElement element, PrintPageEventArgs args )
public: virtual Canvas^ CreateCanvas( UIElement^ element, PrintPageEventArgs^ args )
The PrinterHelper.CreateCanvas method can be used to create the System.Windows.UIElement to use as the visual paramater to the WPF PrintDialog.PrintVisual when using the System.Windows.Controls.PrintDialog class.
This method can also be used to create the System.Windows.UIElement to use as the Silverlight 4.0 and later PrintPageEventArgs.PageVisual property used when printing using the Silverlight 4.0 and later PrintDocument class.
Public Sub PrintViewerCanvasExample(ByVal viewer As ImageViewer) Dim dlg As New PrintDialog() If dlg.ShowDialog() = True Then ' Create the Visual from the viewer Dim ph As New PrinterHelper() ph.Destination = New Rect(0, 0, 1, 1) ph.IsDestinationRelative = True ph.HorizontalAlignment = HorizontalAlignment.Center ph.VerticalAlignment = VerticalAlignment.Center ph.ImageStretch = Stretch.UniformToFill Dim args As New PrintPageEventArgs(New Thickness(), New Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight)) Dim visual As Visual = ph.CreateCanvas(viewer, args) dlg.PrintVisual(visual, "My Document") End If End Sub
public void PrintViewerCanvasExample(ImageViewer viewer) { PrintDialog dlg = new PrintDialog(); if(dlg.ShowDialog() == true) { // Create the Visual from the viewer PrinterHelper ph = new PrinterHelper(); ph.Destination = new Rect(0, 0, 1, 1); ph.IsDestinationRelative = true; ph.HorizontalAlignment = HorizontalAlignment.Center; ph.VerticalAlignment = VerticalAlignment.Center; ph.ImageStretch = Stretch.UniformToFill; PrintPageEventArgs args = new PrintPageEventArgs(new Thickness(), new Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight)); Visual visual = ph.CreateCanvas(viewer, args); dlg.PrintVisual(visual, "My Document"); } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2