Question PrintForm problems - Form too large / Letter sized printout

nameofperson

New member
Joined
Feb 15, 2012
Messages
1
Location
Mexico City, Mexico, Mexico
Programming Experience
3-5
Hello all, hopefully you can help me.
I'm developing a small application that requires printouts of specific reports (which would be too time-consuming to rebuild in MS Reports), and I'm having a strange issue with Portrait Mode.
I basically just made a form, put a picturebox on the back with an image of the blank report, and then just put labels and textboxes on the appropriate places. Landscape mode prints just fine with the PrintForm control (since it fits on the monitor resolution), but Portrait only prints a section. I've already tried with the Scrollable option on the Print method and AutoSize and AutoScroll on the form, but it still only prints up to the max screen resolution (my image is 1000px, only prints about 900px).

Having said that, a strange thing happens if I move the window with the mouse. The scrollbar disappears, and the printout does get the full client area, BUT without any of the controls on my form. If I use the regular Print method, controls do appear on the printout but it's cropped at 900px. If I do the move programmatically, it still crops it, it is only when I move the window with the mouse (even if it's like 2px).Tried to trace the change with breakpoints but I still came out empty, I only know it happens on the Form.Move event.

I've already trawled through Google looking for solutions, and most involve taking a screen cap or BitBlt to a second picturebox and printing it off there. The thing is that PrintForm already reduces the quality, taking a screen cap would only reduce the quality further, plus the form would still be missing a piece since it doesn't fit in the screen.Redoing the report using GDI+ commands onto a Graphics object would also be too time-consuming (since I have 10 2-page reports with different layouts).I do have the original formats in Excel, and the form receives the print data in a Dataset, so if there were an alternative method involving those it would be very helpful.


Anyway, here's a bit of my code:
'full client area, no controls
PrintForm2.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
 'controls ok, printout cropped
PrintForm2.Form=frmVerEst
PrintForm2.Print()

'full print logic
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        'get the report form (print is initiated from other form)
        Dim TargetReport As Form = Form.ActiveForm
        'choose orientation and adjust margins
        If PrintOrientation = 0 Then
            PrintDialog1.PrinterSettings.DefaultPageSettings.Landscape = True
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Left = 20
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Right = 20
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Bottom = 10
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Top = 28
        Else
            PrintDialog1.PrinterSettings.DefaultPageSettings.Landscape = False
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Left = 10
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Right = 10
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Bottom = 10
            PrintDialog1.PrinterSettings.DefaultPageSettings.Margins.Top = 20
        End If
        TargetReport.Focus()
'show print dialog with options selected
        If PrintDialog1.ShowDialog = DialogResult.OK Then
            PrintForm1.PrinterSettings = PrintDialog1.PrinterSettings
            TargetReport.Focus()
            PrintForm1.Form = TargetReport
'choose print method based on orientation
            If PrintOrientation = 0 Then
                PrintForm1.Print()
            Else
                PrintForm1.Print(TargetReport, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
            End If
        End If
    End Sub


Any reply would be most useful, thank you all!
 
Top Bottom