OK, here is the version that Herfried Wagner posted. Note that this returns
hard margins in 1/100ths of an inch so modify as desired to get your
measurement units.
Before calling this use GetHdc() and ReleaseHdc() on the Graphics to get the
device contect to use for the call. I just get and release immediately
before calling GetHardMargins.
BTW you need to search microsoft.public.dotnet.languages.vb to find this.
Ron Allen
Public Declare Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hDc As IntPtr, _
ByVal funct As Int32 _
) As Int32
Private Const PHYSICALOFFSETX As Int32 = 112
Private Const PHYSICALOFFSETY As Int32 = 113
Private Const HORZRES As Int32 = 8
Private Const VERTRES As Int32 = 10
Private Const HORZSIZE As Int32 = 4
Private Const VERTSIZE As Int32 = 6
Public Sub GetHardMargins( _
ByVal hDC As IntPtr, _
ByRef Left As Single, _
ByRef Top As Single, _
ByRef Right As Single, _
ByRef Bottom As Single _
)
Dim offx As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETX))
Dim offy As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETY))
Dim resx As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, HORZRES))
Dim resy As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, VERTRES))
Dim hsz As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, HORZSIZE)) / 25.4F ' Screen
width in inches.
Dim vsz As Single = _
Convert.ToSingle(GetDeviceCaps(hDC, VERTSIZE)) / 25.4F ' Screen
height in inches.
Dim ppix As Single = resx / hsz
Dim ppiy As Single = resy / vsz
Left = (offx / ppix) * 100.0F
Top = (offy / ppix) * 100.0F
Bottom = Top + (vsz * 100.0F)
Right = Left + (hsz * 100.0F)
End Sub
///
Chris said:
Ron,
Thanks so much, the page unit is exactly what I was looking for. Also, if
you could post the library routine for discovering the printer's hard
margins
that woud be great. I tried searching the newsgroups you listed for the
vb
translation however was unable to find it.
Thanks
Chris
-----snip---------