We help IT Professionals succeed at work.

Zoom/resize using PrintForm control

daz84 asked
Medium Priority
Last Modified: 2012-05-12
I am looking to print the contents of a form that is on the screen, eventually I will want to print part of the form but not all of it, but that is for another day.

So far I have the form printing using this code
        Dim x As Integer, y As Integer
        PrintForm1.Form = Me
        PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True
        x = PrintForm1.PrinterSettings.DefaultPageSettings.PrintableArea.Width
        y = PrintForm1.PrinterSettings.DefaultPageSettings.PrintableArea.Height
        MsgBox("Printer area: " & vbCrLf & y & " x " & x & vbCrLf & vbCrLf & "Screen area: " & vbCrLf & Me.Width & " x " & Me.Height, , "Printable Area")
        PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview

Open in new window

You can see from my code that I have dropped in a message box to tell me what the resolution of the paper is and what the size of my form is (Printer area is 1113 x 800 and Screen area is 1366 x 768). You will also see I have set it to print preview rather than print, purely to save paper during testing.

My goal is to resize the image of the form to the size of a landscape A4 sheet of paper (which in this case appears to be 1113x800) .

Obviously I cannot simply resize the form, as that would lose some information. I want the entire contents of my form to exactly fit the single sheet of A4.

An hour of googling has got me nowhere and MSDN doesn't seem to be of any use either. Any help is much appreciated!
Watch Question

Most Valuable Expert 2012
Top Expert 2014
I dont think printform component would allow you to zoom as it just takes a form and prints it.

However, if you use this technique to print


you can use a technique such as this to scale the image




Excellent! Thank you. Took a bit to get my head around it but I got it working. I have it changing the resolution to a fixed value and it works perfectly. Once I play around with some properties I am sure I can have it calculating a value from the available printer area, form size etc (the form can change size too!)

This however causes another issue, the code I had in place before this rotated the image to landscape as the layout of my form is better suited to a landscape view. There is clearly no such property for a bitmap so I had a bash at a procedure for this.

    Private Sub Rotate(ByRef bmpImage As Bitmap)
        Dim x As Integer = bmpImage.Width
        Dim y As Integer = bmpImage.Height
        Dim col As Color = New Color

        Dim bmpNew As Bitmap
        bmpNew = New Bitmap(y, x)
        Dim i, j As Integer
        For i = 0 To x - 1
            For j = 0 To y - 1
                col = bmpImage.GetPixel(i, j)
                bmpNew.SetPixel(j, i, col)
        bmpImage = bmpNew
    End Sub

Open in new window

However it appears to output nothing at all, am I missing something obvious?
Most Valuable Expert 2012
Top Expert 2014



That example didn't really help much, I found a better one here

However on implementing that I get the same result, a blank image. Which leads me back to my conclusion that it is not the procedure that is wrong, but my handling of the bitmap object being passed back out of the procedure.

I still feel my rotate procedure should be working, I am convinced that it is my handling of the object that is causing the problem as the procedure for rotation itself seems fairly trivial.


Been experimenting with Scaletransform and Rotatetransform methods but it's nearly 1am. I'll try again after some sleep and some coffee, any more suggestions are welcome in the mean time


Sorry I have kinda abandoned this, I have been side tracked by other projects and am unable to put the time into completing this right now.

Thank you for your answer, I have awarded a B grade for it as it didn't solve my problem but did offer some very useful links which I can use when I get back to this project.