N
Nancy
BlankFollowing is the code I'm using in an attempt to determine the hard
margins of a printer and adjust the print margins accordingly. I'm only
showing the retrieval of info (not the manipulating) for which I'm getting
the same output value, 8.641474E+12, for the width, height, x, and y
parameters. I have no idea what is wrong. I've been searching for code
examples but haven't found a close example for what I'm trying to do - i.e.
determine these values within the PrintPage routine using VB.Net. Is the
handle creation wrong? Can a IntPtr be converted to Long? Thanks for any
help you can offer!
Nancy
Private Const PHYSICALWIDTH As Long = 110
Private Const PHYSICALHEIGHT As Long = 111
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Sub PrintDoc_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim hdcPtr As IntPtr = e.Graphics.GetHdc
Dim hdcLong As Long = hdcPtr.ToInt64
'All numbers in dpi
Dim XRes As Single = e.PageSettings.PrinterResolution.X
Dim YRes As Single = e.PageSettings.PrinterResolution.Y
Dim hardWT As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALWIDTH))
Dim hardHT As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALHEIGHT))
Dim hardX As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALOFFSETX))
Dim hardY As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALOFFSETY))
'Dim hardXRes As Single = GetDeviceCaps(hdcLong, HORZRES)
e.Graphics.ReleaseHdc(hdcPtr)
Debug.WriteLine("*** Printer Hard Margins: ***" & Chr(13) & _
"Width = " & hardWT.ToString & " Height = " & hardHT.ToString &
Chr(13) & _
"X = " & hardX.ToString & " Y = " & hardY.ToString & Chr(13) & _
"X Res = " & XRes.ToString & " Y Res = " & YRes.ToString)
End Sub
margins of a printer and adjust the print margins accordingly. I'm only
showing the retrieval of info (not the manipulating) for which I'm getting
the same output value, 8.641474E+12, for the width, height, x, and y
parameters. I have no idea what is wrong. I've been searching for code
examples but haven't found a close example for what I'm trying to do - i.e.
determine these values within the PrintPage routine using VB.Net. Is the
handle creation wrong? Can a IntPtr be converted to Long? Thanks for any
help you can offer!
Nancy
Private Const PHYSICALWIDTH As Long = 110
Private Const PHYSICALHEIGHT As Long = 111
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Sub PrintDoc_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim hdcPtr As IntPtr = e.Graphics.GetHdc
Dim hdcLong As Long = hdcPtr.ToInt64
'All numbers in dpi
Dim XRes As Single = e.PageSettings.PrinterResolution.X
Dim YRes As Single = e.PageSettings.PrinterResolution.Y
Dim hardWT As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALWIDTH))
Dim hardHT As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALHEIGHT))
Dim hardX As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALOFFSETX))
Dim hardY As Single = ToSingle(GetDeviceCaps(hdcLong, PHYSICALOFFSETY))
'Dim hardXRes As Single = GetDeviceCaps(hdcLong, HORZRES)
e.Graphics.ReleaseHdc(hdcPtr)
Debug.WriteLine("*** Printer Hard Margins: ***" & Chr(13) & _
"Width = " & hardWT.ToString & " Height = " & hardHT.ToString &
Chr(13) & _
"X = " & hardX.ToString & " Y = " & hardY.ToString & Chr(13) & _
"X Res = " & XRes.ToString & " Y Res = " & YRes.ToString)
End Sub