我目前正在浪费大量的纸张试图弄清楚这一点。我有一个名为 Dock 的 Dockpanel,带有堆栈面板、边框和文本框,我希望整个 Dock 打印到一页。
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
'Define Printer Dialog
Dim dialog As New PrintDialog
'Define Printer Capabilities
Dim capabil As PrintCapabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket)
'Scale content to capabilities of printer
Dim scale As Double = Math.Min(capabil.PageImageableArea.ExtentWidth / Dock.ActualWidth, capabil.PageImageableArea.ExtentHeight /
Dock.ActualHeight)
Dock.LayoutTransform = New ScaleTransform(scale, scale)
'Create a margin
Dim pagemargin As Integer = 20
'Define the size of the page
Dim pagesize As New Size(capabil.PageImageableArea.ExtentWidth - pagemargin, capabil.PageImageableArea.ExtentHeight - pagemargin)
Dock.Measure(pagesize)
'Resize dock to optimal page size
Dock.Arrange(New Rect(New Point(capabil.PageImageableArea.OriginWidth, capabil.PageImageableArea.OriginHeight), pagesize))
'Prompt and Print
If dialog.ShowDialog = True Then
dialog.PrintVisual(Dock, "Printed Page.")
End If
End Sub
我不理解这背后的数学原理吗?我应该用另一种方法来解决这个问题吗?
编辑:我面临的问题是,即使扩展坞的大小似乎正确,打印时仍有巨大的左边距和底部边距。我已经尝试调整边距,但似乎起点仍然是关闭的。该页面的顶部和右侧也被截断。