CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    24

    Question .NET Printing Predicament

    EDIT: Forgot to mention: VS2010

    Here's my situation:

    I've done a whole lot of grabbing, formatting and relocating of data and stuck it in a RichTextBox. All good there. The formatted info needs to print. Also good. Unfortunately it is supposed to have page breaks at certain points. No biggy, I'll just use vbFormFeed.

    vbFormFeed does not work with Windows printer Drivers... Great... Also, since it's .NET and not VB6, no Printer object.


    My current printing method (PrintDocument) is as such:

    Code:
    Private Sub prtCheq_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prtCheq.PrintPage
            Static intCurrentChar As Int32
            Dim font As New Font("Courier New", 10, FontStyle.Bold)
    
            Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32
            With prtCheq.DefaultPageSettings
                intPrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
                intPrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
    
                marginLeft = 50 ' X coordinate
                marginTop = 50 ' Y coordinate
    
            End With
    
            If prtCheq.DefaultPageSettings.Landscape Then
                Dim intTemp As Int32
                intTemp = intPrintAreaHeight
                intPrintAreaHeight = intPrintAreaWidth
                intPrintAreaWidth = intTemp
            End If
    
            Dim intLineCount As Int32 = CInt(intPrintAreaHeight / font.Height)
            Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, intPrintAreaWidth + 75, intPrintAreaHeight + 50)
    
            Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
            Dim intLinesFilled, intCharsFitted As Int32
            e.Graphics.MeasureString(Mid(txtFinal.Text, intCurrentChar + 1), font, _
                        New SizeF(intPrintAreaWidth, intPrintAreaHeight), fmt, _
                        intCharsFitted, intLinesFilled)
    
            e.Graphics.DrawString(Mid(txtFinal.Text, intCurrentChar + 1), font, _
                Brushes.Black, rectPrintingArea, fmt)
            intCurrentChar += intCharsFitted
            If intCurrentChar < txtFinal.Text.Length Then
                e.HasMorePages = True
            Else
                e.HasMorePages = False
                intCurrentChar = 0
            End If
        End Sub
    Willing to ditch this whole method if need be. But I don't have a clue how I'm going to do this... perhaps something with an
    Code:
    If currentLine.contains(vbFormFeed) Then
    'new page, page break, w/e
    End If
    What do?
    Last edited by WileeDarklight; November 18th, 2010 at 10:36 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: .NET Printing Predicament

    Printer drivers should be able to format pages.

    http://www.startvbdotnet.com/controls/printdialog.aspx
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured