Print Gets Cut Off - But Only with 2.0

We have a large application having over 30 forms with print buttons. Behind the print button, the code is always:

OurCommonPrintRoutine(Me)

Here's the module code:

FriendSub OurCommonPrintRoutine(ByRef PassedFormAs Form)

Dim iOrigFormTopAsInteger

Dim iOrigFormLeftAsInteger

Dim iScreenWidthAsInteger

Dim iScreenHeightAsInteger

Dim iFormWidthAsInteger

Dim iFormHeightAsInteger

NewPrintForm =New Microsoft.VisualBasic.PowerPacks.Printing.PrintForm(PassedForm)

iScreenWidth =My.Computer.Screen.WorkingArea.Width

iScreenHeight =My.Computer.Screen.WorkingArea.Height

Dim OrientationSettingAs System.Drawing.Printing.PrinterSettings

Dim blnLandscapeAsBoolean

OrientationSetting =New System.Drawing.Printing.PrinterSettings

blnLandscape = OrientationSetting.DefaultPageSettings.Landscape

If PassedForm.Width > PassedForm.HeightThen

OrientationSetting.DefaultPageSettings.Landscape =True

Else

OrientationSetting.DefaultPageSettings.Landscape =False

EndIf

iOrigFormTop = PassedForm.Top

iOrigFormLeft = PassedForm.Left

iFormWidth = PassedForm.Width

iFormHeight = PassedForm.Height

PassedForm.Top = (iScreenHeight - iFormHeight) / 2

PassedForm.Left = (iScreenWidth - iFormWidth) / 2

' above centering probably overkill; temporarily setting .Top and .Left

' to 1 also works to keep form in printable area

NewPrintForm.PrinterSettings = OrientationSetting

NewPrintForm.Print(PassedForm, _

PowerPacks.Printing.PrintForm.PrintOption.FullWindow)

' Last, put everything back like you found it:

OrientationSetting.DefaultPageSettings.Landscape = blnLandscape

PassedForm.Top = iOrigFormTop

PassedForm.Left = iOrigFormLeft

EndSub

The procedure above took some trial and error to write, but works fine with our largest and most complex child forms -- so long as the reference is to PrintForm Component 1.0.

I just tried changing to 2.0, on the theory of best to go with the newest. The problem with 2.0 is that it tries to put large margins (about 1 1/8 inch) at the top and left, resulting in large forms being cut off at the right and bottom.

I tried temporarily putting the printer margins at 1 on all four sides. This can stop the right from being cut off in 2.0, but not the bottom.

Answer is obvious enough - Use 1.0! However, I thought I might be doing something in the realm of dumb and/or or there may be more orthodox solutions.

Thanks for all ideas.

Steve Eisenberg

Pennsylvania, USA

[5351 byte] By [StevenE] at [2008-1-10]
# 1

Hi Steven,

I believe what you're running into is a bug that was actually fixed in PrintForm component v2.0. In 1.0 it did not respect that PrinterSettings Margins, in 2.0 it does.

I would try setting OrientationSetting.DefaultPageSettings.Margins so that the page fits. By Default the margins are set to 100 in hundredths of an inch

JohnHart_MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...