Image of Navigational Panel mapped to Contents / Home / Search Printing Multiple Forms in VB4
Tech Support Question

Image of Line Break

Q. I am working on a project for my grade 13 computer programming class and we are trying to print multiple forms on a single page. We have tried several VB4 books and have no found any solution to our problem.

If you could tell me how to print multiple forms on a single page it would be greatly appreciated.

Thanks.
From: Pete Webb
Email: fox@connect.reach.net

A. Hmmm. This one is somewhat difficult. I am assuming you are using the PrintForm method to have the Forms print themselves to the default printer directly. This is cool but gives you no control whatsoever, hence your problem. I would suggest that you take a different approach. Trying to get an image of the current form for direct manipulation or Blitting to the Printer's hDC is also probably more trouble than it's worth.

I would suggest that you instead write some code to interpret the objects on the form into a series of graphics methods that you can send to the printer, consider the following code.

  Dim iNum As Integer
     
    Printer.Line (0, 0)-(Me.ScaleWidth, Me.ScaleHeight), 0, B
    For iNum = 0 To Me.Controls.Count - 1
      Printer.FontName = Me.Controls(iNum).FontName
      Printer.FontSize = Me.Controls(iNum).FontSize
      Printer.FontBold = Me.Controls(iNum).FontBold
      Printer.FontItalic = Me.Controls(iNum).FontItalic  
      Printer.FontUnderline = Me.Controls(iNum).FontUnderline
      If TypeOf Me.Controls(iNum) Is CommandButton Then
        Printer.Line (Me.Controls(iNum).Left,Me.Controls(iNum).Top)-
                     (Me.Controls(iNum).Width,Me.Controls(iNum).Height), 0, B
        Printer.CurrentX = Me.Controls(iNum).Left + (Printer.TextWidth
                                                    (Me.Controls(iNum).Caption) \ 2)
        Printer.CurrentY = Me.Controls(iNum).Top + (Printer.TextHeight
                                                   (Me.Controls(iNum).Caption) \ 2)
        Printer.Print Me.Controls(iNum).Caption
       ElseIf TypeOf Me.Controls(iNum) Is OptionButton Then
        Printer.Circle (Me.Controls(iNum).Left + 60,Me.Controls(iNum).Left + 600), 100
        If Me.Controls(iNum).Value <> 0 Then
          Printer.FillColor = 0
          Printer.Circle (Me.Controls(iNum).Left + 60,Me.Controls(iNum).Left + 600), 50
        End If
        Printer.CurrentX = Me.Controls(iNum).Left + 10
        Printer.CurrentY = Me.Controls(iNum).Top + 10
        Printer.Print Me.Controls(iNum).Caption
      End If
    Next iNum
    Printer.EndDoc

Essentially we iterate through all the objects on the form and interpret them as a series of commands for the printer. This code is a quick draft, and some of the positioning is off, but it should give you the idea. Just deal with one type of control at a time, when you get the rendering of each control working it doesn't matter how many you have on the form, they will still work.

This may not give you the prettiest output, but it will basically work, also you can parse you second form by simply adding the first form's ScaleHeight to all the vertical positioning of the second form.

Good Luck, I hope this helps you achieve what you need to do.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]