2013-10-10 1 views
0

현재이 문제를 해결하기 위해 엄청난 양의 종이를 낭비하고 있습니다. 스택 패널, 테두리 및 텍스트 상자가있는 독 (Dock)이라는 Dockpanel이 있으며 전체 독을 한 페이지에 인쇄하려고합니다.DockPanel을 인쇄하여 페이지에 맞추기

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 

나는이 문제를 이해하고 있지 않습니까? 내가이 문제에 접근해야하는 또 다른 방법이 있습니까?

EDIT : 내가 직면하고있는 문제는 도크가 올바르게 크기가있는 것처럼 보이지만 인쇄 할 때 거대한 왼쪽 여백과 아래쪽 여백이 있다는 것입니다. 여백을 조정 해 보았지만 시작점이 꺼져있는 것 같습니다. 이 페이지는 오른쪽 상단과 오른쪽 상단에서 잘린 상태입니다.

+0

당신이 지금까지 얻은 것의 무엇이 잘못되었는지 자세히 설명해 줄 수 있습니까? – Daniel

+0

@Doc 죄송합니다. 곧 업데이트 될 것입니다. – GamerJ5

답변

1

이것은 내가 단서를 사용하여 만든 것입니다. PageMediaSize. 이것은 당신이 원하는 것일 수도 아닐 수도 있습니다. 그러나 어떤 경우에 어떤 아이디어를 줄 수 있습니다 :

Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs) 
    Dim dialog As New PrintDialog 
    If dialog.ShowDialog = True Then 
    Dim dockParent As StackPanel = Dock.Parent 
    dockParent.Children.Remove(Dock) 

    Dim vis = PerformTransform(Dock, dialog.PrintQueue) 
    dialog.PrintVisual(vis, "Printed Page.") 

    vis.Children.Remove(Dock) 
    dockParent.Children.Add(Dock) 
    End If 
End Sub 

Private Function PerformTransform(v As Visual, pq As PrintQueue) As ContainerVisual 
    Dim root As ContainerVisual = New ContainerVisual() 
    Const inch As Double = 96 'DPI 

    'Set the margins 
    Dim xMargin = 1.25 * inch 
    Dim yMargin = 1 * inch 

    'Get the user print ticket and media dimensions 
    Dim pt = pq.UserPrintTicket() 
    Dim printableWidth = pt.PageMediaSize.Width.Value 
    Dim printableHeight = pt.PageMediaSize.Height.Value 

    Dim xScale = (printableWidth - xMargin * 2)/printableWidth 
    Dim yScale = (printableHeight - yMargin * 2)/printableHeight 

    root.Children.Add(v) 
    root.Transform = New MatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin) 

    Return root 
End Function 
+0

꽤 있지만 거기에 올바른 방향으로 단계입니다. 내가 마땅히 얻을 수있을 때까지 마진을 가지고 계속 플레이 할 것입니다. – GamerJ5

+0

내가 겪고있는 큰 문제는 페이지의 왼쪽과 아래쪽면에서 큰 차이가 난다는 것입니다. 페이지에서 인쇄를 시작할 위치를 어떻게 정의합니까? – GamerJ5

+1

@ GamerJ5 나는 마진을 많이 얻지 못하기 때문에 너에게 일어난 이상한 일이다. 오늘 밤에 몇 가지 테스트를 수행 할 수 없지만 사용자 설정을 기반으로 할 수 있습니다. 디버거에서'pt' 변수를 체크 아웃하고 실제로 무엇이 포함되어 있는지 확인합니다. 그것은 당신의 기계의 인쇄 설정에 따라 것 같습니다. – Daniel

관련 문제