|
-
Jul 15th, 2005, 05:54 AM
#1
Thread Starter
Lively Member
[RESOLVED] Printing and margins problem
Does anybody know how to find the margins which maximize the print area ?
The default margin are set to 100 and I don't know how to get the printer limit.
Anyhelp would be great
-
Jul 15th, 2005, 07:44 AM
#2
Thread Starter
Lively Member
Re: Printing and margins problem
-
Jul 15th, 2005, 08:44 AM
#3
Re: Printing and margins problem
-
Jul 18th, 2005, 04:47 AM
#4
Thread Starter
Lively Member
Re: Printing and margins problem
OK, it was interesting. I also found an article at this address : http://etc.nkadesign.com/Programming/CSharpSnippets
It retrieves the real margins from the printer. But when I print using these, I don't get what I want.
I tried to set the margins manually to 50/75 inches, the top and left margins where correct but
the bottom and right ones where much smaller. The paper size is correct.
So I don't know what the problem is....
-
Jul 18th, 2005, 09:44 AM
#5
Thread Starter
Lively Member
Re: Printing and margins problem
OK It works,
VB Code:
Public Class PrinterBounds
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As IntPtr, ByVal capindex As Int32) As Int32
Private Const PHYSICALOFFSETX As Integer = 112
Private Const PHYSICALOFFSETY As Integer = 113
Private Const VERTRES As Integer = 10
Private Const HORZRES As Integer = 8
Private Const PHYSICALWIDTH As Integer = 110
Private Const PHYSICALHEIGHT As Integer = 111
Public Function PrinterBounds(ByVal g As System.Drawing.Graphics) As System.Drawing.Printing.Margins
Dim hDC As IntPtr
Dim PageRes As Point
Dim Offset As Point
Dim PhysicalDim As Point
Dim Top As Integer
Dim Left As Integer
Dim Bottom As Integer
Dim Right As Integer
PageRes = New Point
Offset = New Point
hDC = g.GetHdc()
Offset.X = GetDeviceCaps(hDC, PHYSICALOFFSETX)
Offset.Y = GetDeviceCaps(hDC, PHYSICALOFFSETY)
PhysicalDim.X = GetDeviceCaps(hDC, PHYSICALWIDTH)
PhysicalDim.Y = GetDeviceCaps(hDC, PHYSICALHEIGHT)
PageRes.Y = GetDeviceCaps(hDC, VERTRES)
PageRes.X = GetDeviceCaps(hDC, HORZRES)
g.ReleaseHdc(hDC)
Left = CInt(Offset.X * 100.0 / g.DpiX)
Top = CInt(Offset.Y * 100.0 / g.DpiY)
Right = CInt((PhysicalDim.X - PageRes.X - Offset.X) * 100.0 / g.DpiX)
Bottom = CInt((PhysicalDim.Y - PageRes.Y - Offset.Y) * 100.0 / g.DpiY)
Return New System.Drawing.Printing.Margins(0, Right + Left, 0, Bottom + Top)
End Function
The last line is a little weird, but we have to apply an offset of (-Left,-Top) to the margins, so , that's it.
For some weird reason, I haven't been able to print within the margins with Display as PageUnit (it's 1/75 inches).
So I turned PageUnit to Inches and it works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|