Results 1 to 8 of 8

Thread: [RESOLVED] Clear last Document in Printdocument

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    9

    Resolved [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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    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.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Clear last Document in Printdocument

    Quote Originally Posted by techgnome View Post
    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

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Clear last Document in Printdocument

    Quote Originally Posted by .paul. View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    9

    Thumbs up Re: Clear last Document in Printdocument

    Quote Originally Posted by techgnome View Post
    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 = ''".

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    9

    Re: Clear last Document in Printdocument

    Thank you,

    Global Variables it is.

    Based on my code, I just set TextToPrint = "", and it worked.

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width