Reputation: 11
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
I have done coding in vb.net 2022 in windows 10 platform... and build setup in windows 10.. and I run the setup in windows 11.. and the app runs fine... but when I print the document, it doesn't run like which has been printed in the windows 10 platform.. do you have any suggestions..
note: I have changed the coding on "Dim adjustDGVtoA4 As New Rectangle(60, 300, e.PageBounds.Width - 120, e.PageBounds.Height - 600) " and print in windows 11, it is ok... but when I print in windows 10, it is not ok.
thank you...
"translation to english"
Print in Windows 10 before editing code...
Print in Windows 11 before editing code...
Print in Windows 10, after editing code
Upvotes: 0
Views: 174
Reputation: 11
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
I tried to do this, and it worked ok.. where the printdocument had to create two OSVersions...
so does anyone have any other suggestions...
thanks for all...
Upvotes: 0