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
Printable View
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
Anyone ?
Try this article
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.... :confused:
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.