Hi Jack,
can you try this code, it calculates the page and image width in centimeters
keeping track of the image resolution. Then it calculates where the image
should be drawn so that the right sides are aligned. You can try it with
with to images of the same pixel size but different resolutions to see if it
works.
PS: you can ofcourse change the code so it works in inches but for me it was
easier to do it in centimeters
Hth Greetz Peter
Private Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage
Try
Dim intPrintAreaHeight, intPrintAreaWidth As Int32
Dim xPrint, yPrint As Double
With pdoc.DefaultPageSettings
intPrintAreaHeight = ((.PaperSize.Height / 100) * 2.54) -
((.Margins.Top / 100) * 2.54) - ((.Margins.Bottom / _ 100) * 2.54)
intPrintAreaWidth = ((.PaperSize.Width / 100) * 2.54) -
((.Margins.Left / 100) * 2.54) - ((.Margins.Right / 100) _ * 2.54)
xPrint = ((.Margins.Left / 100) * 2.54) ' X coordinate
yPrint = .Margins.Top ' Y coordinate doesn't need to be
recalculated in this scenario
End With
' If the user selected Landscape mode, swap the printing area
height
' and width.
If pdoc.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = intPrintAreaHeight
intPrintAreaHeight = intPrintAreaWidth
intPrintAreaWidth = intTemp
End If
Dim newImage As Image = Image.FromFile("c:\1.jpg")
Dim realImageWidth As Double
realImageWidth = (newImage.Width /
newImage.HorizontalResolution) * 2.54
realImageWidth = (xPrint + intPrintAreaWidth) - realImageWidth
realImageWidth = (realImageWidth * 100) / 2.54
Dim ulCorner As New Point(realImageWidth, yPrint)
' Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner)
yPrint += newImage.Height + 10
newImage.Dispose()
newImage = Image.FromFile("c:\2.jpg")
realImageWidth = (newImage.Width /
newImage.HorizontalResolution) * 2.54
realImageWidth = (xPrint + intPrintAreaWidth) - realImageWidth
realImageWidth = (realImageWidth * 100) / 2.54
ulCorner = New Point(realImageWidth, yPrint)
e.Graphics.DrawImage(newImage, ulCorner)
e.HasMorePages = False
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub