Results 1 to 5 of 5

Thread: [RESOLVED] Printing and margins problem

  1. #1

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    Resolved [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

  2. #2

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    Re: Printing and margins problem

    Anyone ?

  3. #3
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Printing and margins problem


  4. #4

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    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....

  5. #5

    Thread Starter
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82

    Re: Printing and margins problem

    OK It works,
    VB Code:
    1. Public Class PrinterBounds
    2.  
    3.         Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As IntPtr, ByVal capindex As Int32) As Int32
    4.  
    5.         Private Const PHYSICALOFFSETX As Integer = 112
    6.         Private Const PHYSICALOFFSETY As Integer = 113
    7.         Private Const VERTRES As Integer = 10
    8.         Private Const HORZRES As Integer = 8
    9.         Private Const PHYSICALWIDTH As Integer = 110
    10.         Private Const PHYSICALHEIGHT As Integer = 111
    11.        
    12.         Public Function PrinterBounds(ByVal g As System.Drawing.Graphics) As System.Drawing.Printing.Margins
    13.             Dim hDC As IntPtr
    14.             Dim PageRes As Point
    15.             Dim Offset As Point
    16.             Dim PhysicalDim As Point
    17.  
    18.             Dim Top As Integer
    19.             Dim Left As Integer
    20.             Dim Bottom As Integer
    21.             Dim Right As Integer
    22.  
    23.             PageRes = New Point
    24.  
    25.             Offset = New Point
    26.  
    27.             hDC = g.GetHdc()
    28.  
    29.             Offset.X = GetDeviceCaps(hDC, PHYSICALOFFSETX)
    30.             Offset.Y = GetDeviceCaps(hDC, PHYSICALOFFSETY)
    31.             PhysicalDim.X = GetDeviceCaps(hDC, PHYSICALWIDTH)
    32.             PhysicalDim.Y = GetDeviceCaps(hDC, PHYSICALHEIGHT)
    33.  
    34.             PageRes.Y = GetDeviceCaps(hDC, VERTRES)
    35.             PageRes.X = GetDeviceCaps(hDC, HORZRES)
    36.             g.ReleaseHdc(hDC)
    37.  
    38.             Left = CInt(Offset.X * 100.0 / g.DpiX)
    39.             Top = CInt(Offset.Y * 100.0 / g.DpiY)
    40.             Right = CInt((PhysicalDim.X - PageRes.X - Offset.X) * 100.0 / g.DpiX)
    41.             Bottom = CInt((PhysicalDim.Y - PageRes.Y - Offset.Y) * 100.0 / g.DpiY)
    42.  
    43.             Return New System.Drawing.Printing.Margins(0, Right + Left, 0, Bottom + Top)
    44.         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
  •  



Click Here to Expand Forum to Full Width