I have an mdi application into which I slotted PrintForm. This seemd to work well until suddenly I was getting only part of the form printed or previewed. Further testing revealed that this only happens when the mdi container is NOT maximised AND the PrinterOption is ClientAreaOnly or Scrollable (or CompatModeCAO). What appears to be printed is the portion of the form that falls into the rectangle that equates to the position of the form if the mdi container was maximised.
It’s easy to replicate this.
- Start a new windows application project in Visual Studio
- Change Form1’s IsMdiContainer to True
- Make the form quite a bit bigger than the default (so there’s no implication of scrolling problems later on)
- Add a button (unconventional, but quick and easy).
- Add a second form
- Add the PrintForm component to Form2
- Add a button to Form2
- Double click the button to create a click event handler
- Add the line
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
- Back to Form1 and double click the button to create a click event handler
- Add the lines
Dim f As New Form2
f.MdiParent = Me
f.Show()
- Run the application
- Make sure it isn’t maximised or at the very top left of the Windows Desktop
- Click the button on Form1 to launch Form2
- Click the button on Form2 to display the Print Preview
- Only a small portion of the form will be shown in the Preview
I found a workaround for this, which is to detatch Form2 from the mdi container for the duration of the Preview. In the above code that can be done by replacing the Form2 Button1 click event code with:
- Dim pf As Form = MdiParent
MdiParent = Nothing
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.ClientAreaOnly)
MdiParent = pf
This works a treat. However, when I did this in my real application I got the problem that the Form (equivalent to Form2 above) jumps to a different location whilst it is detatched from the mdi container. To get around this, I had to find the real screen coordinates and force the form to use those whilst the PrintForm was active. I also had to refresh the controls, or the display was a mess of half drawn controls. Here’s what worked for me, using the code from my real application.
' PrtForm is in effect “Me”, passed into this code
Dim parentForm As Form = PrtForm.MdiParent
Dim absoluteLocation As System.Drawing.Point = _
PrtForm.ParentForm.PointToScreen(New System.Drawing.Point _
(PrtForm.Location.X + 2, PrtForm.Location.Y + 2))
Dim saveLocation As System.Drawing.Point = PrtForm.Location
' hide form whilst we fiddle
PrtForm.Hide()
PrtForm.MdiParent = Nothing
Dim saveMenu As MainMenu = PrtForm.Menu
PrtForm.Menu = Nothing
PrtForm.Location = absoluteLocation
' now reshow it and refresh the controls
PrtForm.Show()
PrtForm.Refresh()
PrintForm1.Print(PrtForm, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
' put everything back !!
PrtForm.Hide()
PrtForm.Location = saveLocation
PrtForm.Menu = saveMenu
PrtForm.MdiParent = parentForm
PrtForm.Show()
I hope this helps somebody !!

PrintForm bug with MDI code
j1m68
Thanks very much for letting us know. We'll investigate this further