我刚刚开始研究现有的VB项目,最终用户希望能够将WPF窗口作为整页打印到打印机。我在C#中找到了这个代码示例,它在C#中运行得很好
Printing WPF Window to Printer and Fit on a Page
然而,当我尝试将其转换为VB时,我遇到了两个错误
我有点知道Drawing.Size和Windows.Size的区别是基于这个(以及其他几个)SO线程What is the difference between System.Drawing.Point and System.Windows.Point?,但我无法弄清楚如何修改我的翻译方式我可以在VB中以C#的方式进行转换。错误出现在Measure(sz)和Arrange(新的Rect(.....)行。
上)我需要做些什么来完成这项工作?
Private Sub PrintWindow()
Dim printDlg As PrintDialog = New PrintDialog()
If printDlg.ShowDialog() = True Then
Dim capabilities As System.Printing.PrintCapabilities =
printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket)
Dim scale As Double = Math.Min(capabilities.PageImageableArea.ExtentWidth / ActualWidth,
capabilities.PageImageableArea.ExtentHeight / ActualHeight)
LayoutTransform = New ScaleTransform(scale, scale)
Dim sz As New Size(CInt(capabilities.PageImageableArea.ExtentWidth),
CInt(capabilities.PageImageableArea.ExtentHeight))
Measure(sz)
Arrange(New Rect(New Point(CInt(capabilities.PageImageableArea.OriginWidth),
CInt(capabilities.PageImageableArea.OriginHeight)), sz))
printDlg.PrintVisual(Me, "First Fit to Page WPF Print")
End If
End Sub
答案 0 :(得分:1)
为什么不做这样的事情?
Dim sz As New System.Windows.Size(CInt(capabilities.PageImageableArea.ExtentWidth),
CInt(capabilities.PageImageableArea.ExtentHeight))
Arrange(New Rect(New System.Windows.Point(CInt(capabilities.PageImageableArea.OriginWidth),
CInt(capabilities.PageImageableArea.OriginHeight)), sz))