How to make a Print Preview

Hi! Can somebody help me how to make a print preview in print forms
and manual printing.

Comments

  • : Hi! Can somebody help me how to make a print preview in print forms
    : and manual printing.
    :
    :
    Hi, ,don't know if you allready got the code.
    But i did find some example(code) on www.vb-helper.com that whould do the trick.

    SO IT'S NO CODE OF MINE, i'm only using it and it does the job.

    Have fun....

    The program uses a single routine, DrawPrintout, to draw on either a PictureBox or on the Printer object. This routine takes as a parameter the object on which it should draw.


    ' Send the "printout" to the object. The object is
    ' either a PictureBox for preview, or the Printer.
    Private Sub DrawPrintout(obj As Object)
    Const INCH = 1440 ' 1440 twips per inch
    Const TXT = "Here is some sample output."

    ' Make sure the object uses the right font.
    obj.Font.Bold = False
    obj.Font.Italic = False
    obj.Font.Name = "Arial"
    obj.Font.StrikeThrough = False
    obj.Font.Underline = False
    obj.Font.Size = 8

    obj.CurrentX = INCH / 2
    obj.CurrentY = INCH / 2
    obj.Print TXT
    obj.Line (INCH / 4, INCH / 4)-Step(2880, 1440), , B

    obj.CurrentX = Printer.ScaleLeft + Printer.ScaleWidth / _
    2
    obj.CurrentY = Printer.ScaleTop
    obj.Line -(Printer.ScaleLeft + Printer.ScaleWidth, _
    Printer.ScaleTop + Printer.ScaleHeight / 2)
    obj.Line -(Printer.ScaleLeft + Printer.ScaleWidth / 2, _
    Printer.ScaleTop + Printer.ScaleHeight)
    obj.Line -(Printer.ScaleLeft, Printer.ScaleTop + _
    Printer.ScaleHeight / 2)
    obj.Line -(Printer.ScaleLeft + Printer.ScaleWidth / 2, _
    Printer.ScaleTop)
    End Sub



    To display a print preview, the program makes the print preview form's PictureBox half the size of the printer (the whole printer won't fit on the screen). It sizes the form to fit and makes the PictureBox use the same coordinates as the Printer. It then calls DrawPrintout, passing it the PictureBox, and displays the preview form.


    ' Display a preview.
    Private Sub CmdPreview_Click()
    ' Make the preview PictureBox half the size
    ' of the Printer.
    PreviewForm.PreviewPicture.Width = _
    Printer.Width / 2 + _
    PreviewForm.PreviewPicture.Width - _
    PreviewForm.PreviewPicture.ScaleWidth
    PreviewForm.PreviewPicture.Height = _
    Printer.Height / 2 + _
    PreviewForm.PreviewPicture.Height - _
    PreviewForm.PreviewPicture.ScaleHeight

    ' Size the preview form to fit.
    PreviewForm.Height = _
    PreviewForm.PreviewPicture.Height + _
    PreviewForm.Height - PreviewForm.ScaleHeight
    PreviewForm.Width = _
    PreviewForm.PreviewPicture.Width + _
    PreviewForm.Width - PreviewForm.ScaleWidth

    ' Make the preview PictureBox use the same
    ' scaling as the Printer.
    PreviewForm.PreviewPicture.ScaleLeft = Printer.ScaleLeft
    PreviewForm.PreviewPicture.ScaleTop = Printer.ScaleTop
    PreviewForm.PreviewPicture.ScaleWidth = _
    Printer.ScaleWidth
    PreviewForm.PreviewPicture.ScaleHeight = _
    Printer.ScaleHeight

    ' Clear the preview PictureBox.
    PreviewForm.PreviewPicture.Cls

    ' Draw the "printout" on a PictureBox.
    DrawPrintout PreviewForm.PreviewPicture

    ' Display the PictureBox.
    PreviewForm.Show vbModal
    End Sub



    To make a printout, the program simply calls DrawPrintout, passing it the Printer object.


    ' Create a printout.
    Private Sub CmdPrint_Click()
    ' Draw the "printout" on the Printer object.
    DrawPrintout Printer

    ' Finish the printout.
    Printer.EndDoc
    End Sub



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion