Hi. My project is like this. I want to print another document with different content while the program is still running. Like the coding below, after the 1st content (QuantityString, TypeString, PriceDecimal) is previewed, I close the print preview form. But when I put content for the 2nd document, the print preview will show the 1st content as well. I don't want to close the main form everytime I want to print the document.
Thank you for helping me.
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont As New Font("Arial", 12)
Dim HeadingFont As New Font("Arial", 14, FontStyle.Bold)
Dim LineHeightsingle As Single = PrintFont.GetHeight + 2
Dim Column1HorizontalLocationSingle As Single = e.MarginBounds.Left
Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top
Dim Column2HorizontalLocationSingle As Single = 300
Dim Column3HorizontalLocationSingle As Single
Dim PrintLineString As String
Dim FontSizeF As New SizeF
Dim FormattedPriceString As String
PrintLineString = "Mine Coffee Sales"
e.Graphics.DrawString(PrintLineString, HeadingFont, Brushes.Black, Column2HorizontalLocationSingle, VerticalPrintLocationSingle)
PrintLineString = "by Lee"
VerticalPrintLocationSingle += LineHeightsingle
e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, Column2HorizontalLocationSingle, VerticalPrintLocationSingle)
VerticalPrintLocationSingle += LineHeightsingle * 2
For Each IndividualCoffeeSale As CoffeeSale In TransactionCoffeeSale
If IndividualCoffeeSale.QuantityString <> "" Then
e.Graphics.DrawString(IndividualCoffeeSale.QuantityString, PrintFont, Brushes.Black, Column1HorizontalLocationSingle, VerticalPrintLocationSingle)
e.Graphics.DrawString(IndividualCoffeeSale.TypeString, PrintFont, Brushes.Black, Column2HorizontalLocationSingle, VerticalPrintLocationSingle)
FormattedPriceString = FormatNumber(IndividualCoffeeSale.PriceDecimal)
FontSizeF = e.Graphics.MeasureString(FormattedPriceString, PrintFont)
Column3HorizontalLocationSingle = 550 - FontSizeF.Width
e.Graphics.DrawString(FormattedPriceString, PrintFont, Brushes.Black, Column3HorizontalLocationSingle, VerticalPrintLocationSingle)
End If
Next
VerticalPrintLocationSingle += LineHeightsingle * 2
End Sub