Results 1 to 7 of 7

Thread: [RESOLVED] Set Print Margins

  1. #1

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Resolved [RESOLVED] Set Print Margins

    As part of this project I'm doing for VB class I'm required to print out an image of the form. The catch is that we haven't even learned printing yet, so the teacher said to just try and find it on your own. I think there's a section on it in the book but it's only about printing text files and not the form.

    Anyways, the form is exactly 1024 x 780 so I have it set to landscape to fit better, but it still hangs off by an inch or so on the top and left margins.

    Here where I got the code from
    http://www.knowdotnet.com/articles/printform.html

    I tried going under .DefaultPrintSettings and using Offset and Margins but changing them did nothing.

    I should also add that I know my printer can't print on every part of a page and that some of the image will be cut off, but I have been able to print within 1/2 inch of the edge of the paper before and when I print the form image it cuts it of at like 1 1/2 inches.
    Last edited by Vectris; Apr 20th, 2009 at 07:21 PM.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Set Print Margins

    to fit your form image on the screen, you'll need to scale the image down.

    that example is out of date. you don't need the APIs. search the forum for graphics.copyfromscreen

  3. #3

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Set Print Margins

    I'll search for that. As for the "image", I don't really have just an image, it's the Form. The APIs just turned a screenshot of the Form into an image to print. The Form fits fine on screen, but when printing the form it doesn't fit to the paper right, it's off-center and the sides are cut off.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Set Print Margins

    its an image of the form, therefore you do just have an image. you print it the same as you would any image.

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

    Re: Set Print Margins

    Code to print an image (in variable img ) in a defined rectangle (from the upcoming book ;-) )

    vb Code:
    1. Public Enum VerticalAlignments
    2.         Top = 1
    3.         Centre = 2
    4.         Bottom = 3
    5.     End Enum
    6.     Public Enum HorizontalAlignments
    7.         Left = 1
    8.         Centre = 2
    9.         Right = 3
    10.     End Enum
    11.     'If the image is larger than the printable area, clip it,
    12.     'otherwise align it within the printable area
    13.     Dim xOffset As Integer, yOffset As Integer
    14.     Select Case VerticalAlignment
    15.       Case VerticalAlignments.Top
    16.            'Align image at top of printable area
    17.            yOffset = 0
    18.       Case VerticalAlignments.Centre
    19.            'Align image at the middle of printable area
    20.            yOffset = CInt((img.Height / 2) _
    21.                     - (BoundingRectangle.Height / 2))
    22.       Case VerticalAlignments.Bottom
    23.           'Align image at bottom of printable area
    24.           yOffset = img.Height - BoundingRectangle.Height
    25.     End Select
    26.     Select Case HorizontalAlignment
    27.       Case HorizontalAlignments.Left
    28.            xOffset = 0
    29.       Case HorizontalAlignments.Centre
    30.            xOffset = CInt((img.Width / 2) - _
    31.               (BoundingRectangle.Width / 2))
    32.       Case HorizontalAlignments.Right
    33.            xOffset = img.Width - BoundingRectangle.Width
    34.     End Select
    35.  
    36.     Dim SourceArea As New Rectangle(0, 0, _
    37.         BoundingRectangle.Width, BoundingRectangle.Height)
    38.                    
    39.     If img.Width > BoundingRectangle.Width Then
    40.          SourceArea.X += xOffset
    41.     Else
    42.          SourceArea.X -= xOffset
    43.     End If
    44.          
    45.     If img.Height > BoundingRectangle.Height Then
    46.           SourceArea.Y += yOffset
    47.     Else
    48.           SourceArea.Y -= yOffset
    49.     End If
    50.  
    51.     Canvas.DrawImage(img, BoundingRectangle, SourceArea, _
    52.         GraphicsUnit.Pixel)

  6. #6

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Set Print Margins

    Thanks, but that's a lot larger than what I previously had. I suppose I'll still try it as nothing is working so far but the other problem is I can't get a successful image of the form to put in variable img.

    Paul, I tried using copyfromscreen but when I printed, the image was only 1x1inch wide! It was tiny! I just used Me.Location, Point.Empty, and Me.Size as the parameters so I don't know why it was so small.

    Also I found out that the API way isn't working perfectly either, it's still missing a few parts of the form, and it's not because it's being cut off by the printer margins because its more so on some sides than others.

    So basically I need to start over, I need some code to take a full screenshot of just the form and to then print it out (I have part of the print code, involving a print dialog) and for the printout to not be tiny or missing parts of the image.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  7. #7

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Set Print Margins

    Ok, the API that I had to take the screenshot of the form would actually take a shot of the whole form but it also included anything in the background but made it white. So basically the form was in the center of the image with any of the desktop space around it but plain white. So then I found a resize image code and shrunk it down to fit on the paper and that has worked the best.

    Thanks to all for the advice.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

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