Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15537

VS 2013 Clear last Document in Printdocument

$
0
0
Hi, I just cannot find a solution to this. When I print a document, it also prints the last documents, My code is as follows:

Private Sub Print()
Try
PrintDocument2 = New PrintDocument
PrintHeader3()
Dim printControl = New Printing.StandardPrintController
PrintDocument2.PrintController = printControl
PrintDocument2.Print()
Catch ex As Exception
MsgBox(ex.Message)
End Try
MyCn.Close()
Me.Dispose()
txtAmt.Text = ""
txtRem.Text = ""
End Sub

Private Sub PrintHeader3()
Dim Linelen As Integer
Dim StringToPrint As String
strFont = New Font("Arial", 10, FontStyle.Regular)
StringToPrint = COMPNAME
Linelen = StringToPrint.Length
Dim spcLen1 As New String(" "c, Math.Round((40 - Linelen) / 2))
TextToPrint &= spcLen1 & StringToPrint & Environment.NewLine

StringToPrint = "CASH DRAWINGS"
Linelen = StringToPrint.Length
Dim spcLen2 As New String(" "c, Math.Round((40 - Linelen) / 2))
TextToPrint &= spcLen2 & StringToPrint & Environment.NewLine & Environment.NewLine
TextToPrint &= Date.Now.ToString("dd MMM yyyy hh:mm tt")
'TextToPrint &= StringToPrint & Environment.NewLine
spcLen2 = Space(5)
TextToPrint &= spcLen2 & MUSER & Environment.NewLine
TextToPrint &= "_____________________________________" & Environment.NewLine
TextToPrint &= Environment.NewLine
StringToPrint = "Amount - "
spcLen2 = Space(5)
TextToPrint &= spcLen2 & StringToPrint
TextToPrint &= txtAmt.Text & Environment.NewLine & Environment.NewLine
StringToPrint = "Remarks - "
spcLen2 = Space(5)
TextToPrint &= spcLen2 & StringToPrint
StringToPrint = txtRem.Text
TextToPrint &= StringToPrint & Environment.NewLine & Environment.NewLine & Environment.NewLine & Environment.NewLine
StringToPrint = "Signature __________________"
spcLen2 = Space(5)
TextToPrint &= spcLen2 & StringToPrint
TextToPrint &= Environment.NewLine
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
e.Graphics.Clear(Color.White)

Static currentChar As New Integer
Dim h, w As New Integer
Dim left, top As New Integer
Dim strFont = New Font("Lucida Sans Typewriter", 9, FontStyle.Regular)
With PrintDocument2.DefaultPageSettings
h = 0
w = 0
left = 0
top = 0
End With
Dim lines As Integer = CInt(Math.Round(h / 1))
Dim b As New Rectangle(left, top, w, h)
Dim format As StringFormat
format = New StringFormat(StringFormatFlags.LineLimit)
Dim line, chars As Integer
e.Graphics.MeasureString(Mid(TextToPrint, currentChar + 1), strFont, New SizeF(w, h), format, chars, line)
e.Graphics.DrawString(TextToPrint.Substring(currentChar, chars), strFont, Brushes.Black, b, format)
currentChar = currentChar + chars
e.HasMorePages = False
End Sub

Would appreciate any help.

Regards

Navin Balkissoon

Viewing all articles
Browse latest Browse all 15537

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>