vb.net 2022 Windows 10 和 Windows 11 中的 PrintDocument

问题描述 投票:0回答:1
 Private Sub PrintDocument2_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage

        Dim adjustToA4 As New Rectangle(0, 0, e.PageBounds.Width, e.PageBounds.Height)
        Dim adjustDGVtoA4 As New Rectangle(5, 300, e.PageBounds.Width - 10, e.PageBounds.Height - 600)

        Dim dm As New Bitmap(Panel1.Width, Panel1.Height)
        Panel1.DrawToBitmap(dm, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
        e.Graphics.DrawImage(dm, adjustToA4)

        Dim dgv As New Bitmap(DataGridView1.Width, DataGridView1.Height)
        DataGridView1.DrawToBitmap(dgv, New Rectangle(0, 0, DataGridView1.Width, DataGridView1.Height))
        e.Graphics.DrawImage(dgv, adjustDGVtoA4)

    End Sub

我已经在 Windows 10 平台中的 vb.net 2022 中完成了编码...并在 Windows 10 中构建了设置...并且我在 Windows 11 中运行了设置...并且应用程序运行良好...但是当我打印文档时,它不像 Windows 10 平台上打印的那样运行..您有什么建议吗..

注意:我已经更改了“Dim adjustmentDGVtoA4 As New Rectangle(60, 300, e.PageBounds.Width - 120, e.PageBounds.Height - 600) ”上的编码并在 Windows 11 中打印,这是可以的......但是当我在 windows 10 中打印时,就不行了。

谢谢你...

“翻译成英文”

编辑代码之前在 Windows 10 中打印...

编辑代码之前在 Windows 11 中打印...

编辑代码后在 Windows 10 中打印

vb.net windows-10 windows-11 printdocument
1个回答
0
投票
 Private Sub PrintDocument2_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage

    If Environment.OSVersion.Version.Build > 22000 Then     'untuk Windows 11 ke atas
        Dim adjustToA4 As New Rectangle(0, 0, e.PageBounds.Width, e.PageBounds.Height)
        Dim adjustDGVtoA4 As New Rectangle(61, 300, e.PageBounds.Width - 122, e.PageBounds.Height - 860) 'adjust DataGridView

        Dim dm As New Bitmap(Panel1.Width, Panel1.Height)
        Panel1.DrawToBitmap(dm, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
        e.Graphics.DrawImage(dm, adjustToA4)

        Dim dgv As New Bitmap(DataGridView1.Width, DataGridView1.Height)
        DataGridView1.DrawToBitmap(dgv, New Rectangle(0, 0, DataGridView1.Width, DataGridView1.Height))
        e.Graphics.DrawImage(dgv, adjustDGVtoA4)
    Else 'untuk Windows 10
        Dim adjustToA4 As New Rectangle(0, 0, e.PageBounds.Width, e.PageBounds.Height)
        Dim adjustDGVtoA4 As New Rectangle(5, 300, e.PageBounds.Width - 10, e.PageBounds.Height - 860)

        Dim dm As New Bitmap(Panel1.Width, Panel1.Height)
        Panel1.DrawToBitmap(dm, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
        e.Graphics.DrawImage(dm, adjustToA4)

        Dim dgv As New Bitmap(DataGridView1.Width, DataGridView1.Height)
        DataGridView1.DrawToBitmap(dgv, New Rectangle(0, 0, DataGridView1.Width, DataGridView1.Height))
        e.Graphics.DrawImage(dgv, adjustDGVtoA4)
    End If

End Sub

我尝试这样做,它工作正常..其中打印文档必须创建两个操作系统版本...

还有人有其他建议吗...

谢谢大家...

© www.soinside.com 2019 - 2024. All rights reserved.