-
Feb 25th, 2021, 10:47 AM
#1
Thread Starter
New Member
[RESOLVED] Clear last Document in Printdocument
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
-
Feb 25th, 2021, 11:12 AM
#2
Re: Clear last Document in Printdocument
When you paste code in this forum, you should select the full code block and press the # button above the message editor window. This will give you a code block, which will retain your indented code.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 25th, 2021, 12:58 PM
#3
Re: Clear last Document in Printdocument
Its hard to read, but it looks like you're missing an .EndDocument...that's what tells the PrintDocument object that you're done with the document and to release it to the printer.
-tg
-
Feb 25th, 2021, 01:46 PM
#4
Re: Clear last Document in Printdocument
 Originally Posted by techgnome
Its hard to read, but it looks like you're missing an .EndDocument...that's what tells the PrintDocument object that you're done with the document and to release it to the printer.
-tg
Are you sure? There's an EndDoc in classic VB, but VB.Net uses e.HasMorePages
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 25th, 2021, 02:37 PM
#5
Re: Clear last Document in Printdocument
 Originally Posted by .paul.
Are you sure? There's an EndDoc in classic VB, but VB.Net uses e.HasMorePages
hmm... apparently I'm not sure then...
aaaaah.... I found it...
bloody global variables...
try clearing them out when you're done... or before you start using them.
geezus that took some serious mental gymnastics to follow...
-tg
-
Feb 26th, 2021, 03:15 AM
#6
Thread Starter
New Member
Re: Clear last Document in Printdocument
 Originally Posted by techgnome
hmm... apparently I'm not sure then...
aaaaah.... I found it...
bloody global variables...
try clearing them out when you're done... or before you start using them.
geezus that took some serious mental gymnastics to follow...
-tg
Thank you,
It worked, based on my code above, I just set TexttoPrint = ''".
-
Feb 26th, 2021, 03:20 AM
#7
Thread Starter
New Member
Re: Clear last Document in Printdocument
Thank you,
Global Variables it is.
Based on my code, I just set TextToPrint = "", and it worked.
-
Feb 26th, 2021, 07:54 AM
#8
Re: Clear last Document in Printdocument
Great, then if your issue is resolves, can you mark this thread as such? You cna do that by usuing th Thread tools at the top right of post #1.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|