0

私は現在、これを理解しようとして途方もない量の紙を無駄にしています. スタックパネル、ボーダー、テキストボックスを備えた Dock という名前のドックパネルがあり、ドック全体を 1 ページに印刷したいと考えています。

    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

この背後にある数学を理解していませんか? これに近づくべき別の方法はありますか?

編集:私が直面している問題は、ドックのサイズが正しいように見えても、印刷時に左と下の余白が大きいことです。マージンを微調整してみましたが、まだ開始点がずれているようです。また、ページの上部と右側が切り取られています。

4

1 に答える 1