|
-
Apr 20th, 2009, 07:15 PM
#1
Thread Starter
Fanatic Member
[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.
-
Apr 20th, 2009, 08:21 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 20th, 2009, 09:03 PM
#3
Thread Starter
Fanatic Member
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.
-
Apr 21st, 2009, 06:52 AM
#4
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 21st, 2009, 01:16 PM
#5
Re: Set Print Margins
Code to print an image (in variable img ) in a defined rectangle (from the upcoming book ;-) )
vb Code:
Public Enum VerticalAlignments
Top = 1
Centre = 2
Bottom = 3
End Enum
Public Enum HorizontalAlignments
Left = 1
Centre = 2
Right = 3
End Enum
'If the image is larger than the printable area, clip it,
'otherwise align it within the printable area
Dim xOffset As Integer, yOffset As Integer
Select Case VerticalAlignment
Case VerticalAlignments.Top
'Align image at top of printable area
yOffset = 0
Case VerticalAlignments.Centre
'Align image at the middle of printable area
yOffset = CInt((img.Height / 2) _
- (BoundingRectangle.Height / 2))
Case VerticalAlignments.Bottom
'Align image at bottom of printable area
yOffset = img.Height - BoundingRectangle.Height
End Select
Select Case HorizontalAlignment
Case HorizontalAlignments.Left
xOffset = 0
Case HorizontalAlignments.Centre
xOffset = CInt((img.Width / 2) - _
(BoundingRectangle.Width / 2))
Case HorizontalAlignments.Right
xOffset = img.Width - BoundingRectangle.Width
End Select
Dim SourceArea As New Rectangle(0, 0, _
BoundingRectangle.Width, BoundingRectangle.Height)
If img.Width > BoundingRectangle.Width Then
SourceArea.X += xOffset
Else
SourceArea.X -= xOffset
End If
If img.Height > BoundingRectangle.Height Then
SourceArea.Y += yOffset
Else
SourceArea.Y -= yOffset
End If
Canvas.DrawImage(img, BoundingRectangle, SourceArea, _
GraphicsUnit.Pixel)
-
Apr 21st, 2009, 03:24 PM
#6
Thread Starter
Fanatic Member
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.
-
Apr 29th, 2009, 09:08 PM
#7
Thread Starter
Fanatic Member
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.
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
|