Question Printing to deposit slips

mrkrntl

New member
Joined
Sep 6, 2023
Messages
1
Programming Experience
Beginner
Hello, I am trying to develop a Win form app that have a preview image of the actual deposit slip but it will print only the text such as denomination, total amount, account #, name, etc. to a deposit slip paper with a size of 21.5x10.5cm.

I think it works similarly on printing to bank cheques.

Any suggestions on how to achieve this on vb.net?
 
The preview will display whatever you tell it to print. If you are printing the same thing in preview and the real print run then you'll see the same thing. If you want something different in the preview then you need to test whether it is a preview and print something different based on that. I haven't tested this but I think you can test the PrintDocument.PrintController.IsPreview property in your PrintPage event handler and, if that's True, print whatever extra you want to display. That might mean a call to DrawImage to draw an image of the deposit slip or it might mean some additional calls to DrawLine and/or DrawString. Note that you might access your PrintDocument directly via a field or via the sender parameter in the PrintPage event handler.
 
I just tested this code and it worked as described above:
VB.NET:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    PrintPreviewDialog1.ShowDialog()
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    e.Graphics.DrawString("This text will always be printed.", Font, Brushes.Black, 50, 50)

    If PrintDocument1.PrintController.IsPreview Then
        e.Graphics.DrawString("This text will only be printed in preview.", Font, Brushes.Black, 50, 100)
    Else
        e.Graphics.DrawString("This text will only be printed in the final run.", Font, Brushes.Black, 50, 150)
    End If
End Sub
 
Back
Top