Is it possible that I could use the VB.net print dialogue tool to print a receipt from a payment? Like If I were able use a ready to print document which I will only be needing to change the amount, cash, change and name before printing. :D

I dont want to use crystal reports because I know its really complicated.
I am just a vb.net beginner here, learned everything I know in just 3 days. xD

yes it is possible , but can you tell me what you want to print ,every time before printing you want to change amount , and name ,which is not a good approach. as you said that you want to print a payment receipt you can do like this

' Make a new Form, add the following controls

    'Button - btnPrint
    'PrintDocument - prnDoc
    'TextBox - txtNotes

    Dim StringToPrint As String

    'This variable will hold the text to be printed and is assigned in the button press event before the printing is called.

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click

        StringToPrint = txtNotes.Text
        prnDoc.Print()

    End Sub

    'Actual printing code is done by overiding the printpage method of the PrintDocument object. This function will have codes to print the content of the textbox without breaking and spreading out of the page.

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

        Dim numChars As Integer

        Dim numLines As Integer

        Dim stringForPage As String

        Dim strFormat As New StringFormat()

        Dim PrintFont As Font

        PrintFont = txtNotes.Font

        Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)

        Dim sizeMeasure As New SizeF(e.MarginBounds.Width, e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))

        strFormat.Trimming = StringTrimming.Word

        e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)

        stringForPage = StringToPrint.Substring(0, numChars)

        e.Graphics.DrawString(stringForPage, PrintFont, Brushes.Black, rectDraw, strFormat)

        If numChars < StringToPrint.Length Then

            StringToPrint = StringToPrint.Substring(numChars)

            e.HasMorePages = True

        Else

            e.HasMorePages = False

        End If

    End Sub

hope this will helps you :)

Regards

Ohhh ohh! thank you! I'll try to use these codes. Yes I would want to change the name, amount to pay and the amount of cash they'd pay. ^^ May I know why is it not a good approach?

yes , because for receipts we use reports , you can use any reporting tool , this will error free , fast and handsome approach .

This article has been dead for over six months. Start a new discussion instead.