Hi Guys :)..

I hope you fine :),

I need the best and easist way for printing the form ,nested of PrintForm tool
coz it is very bad :angry:,it prints the form like screen shot :angry: ,what I want print entire form on A4 ...
Any suggestions ? :(

Thanks for your help :)

Edited 6 Years Ago by Sara Tech: n/a

Can't say its the best way.
Can't say its the easiest way.

Can say its a way.


Drag a PrintDialog and a PrintDocument to the form.

Set the PrintDialog's Document to the PrintDocument.

Set the Form's KeyPreview Property to True.

Copy and paste the below code in your form.

Press Ctrl + Alt + P to open the Print Dialog.

Change your paper size to A4 and print.

Should scale the form to fit the page.

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As  System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    Dim myImage As New Bitmap(Me.Width, Me.Height)
    Dim PrintSize As Size = e.MarginBounds.Size
    Dim scale As Double = 1

    Me.DrawToBitmap(myImage, New Rectangle(Point.Empty, Me.Size))

    PrintSize.Width *= 0.96 'convert to pixels
    PrintSize.Height *= 0.96

    If myImage.Width > PrintSize.Width Then
        'Form is to big. Scale it down.
        scale = PrintSize.Width / myImage.Width
        e.Graphics.ScaleTransform(scale, scale)
    End If

    If (myImage.Height * scale) > PrintSize.Height Then
        'The form is still to big. Scale it again.
        scale = PrintSize.Height / (myImage.Height * scale)
        e.Graphics.ScaleTransform(scale, scale)
    End If

    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    e.Graphics.DrawImage(myImage, e.MarginBounds.Location)

    myImage.Dispose()

End Sub

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    If e.KeyCode = Keys.P AndAlso (e.Control AndAlso e.Alt) Then
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PrintDocument1.Print()
        End If
    End If

End Sub

Thanks alot Unhnd_Exception for your replay :)
I will try that code and I will tell you what happend.
Thanks again
:)

This question has already been answered. Start a new discussion instead.