Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ive come up with this so far pretty unstructured as yet but works slow.

 

   Private Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage
       Dim iMargin As Integer = 15
       Dim margin As Integer = 10
       Dim i As Integer = 0
       Dim theWord As String = ""
       Dim iPos As Integer
       Dim TextLine As String
       Dim bLine As Boolean = False
       Dim fmt As New StringFormat()

       fmt.FormatFlags = StringFormatFlags.LineLimit
       Printer.PrinterSettings.DefaultPageSettings.Margins.Left = 75
       Printer.PrinterSettings.DefaultPageSettings.Margins.Right = 75
       Printer.PrinterSettings.DefaultPageSettings.Margins.Top = 40
       Printer.PrinterSettings.DefaultPageSettings.Margins.Bottom = 40
       Dim rectPrintingArea As New RectangleF(Printer.PrinterSettings.DefaultPageSettings.Margins.Left, _
                                              Printer.PrinterSettings.DefaultPageSettings.Margins.Top, _
                                              Printer.PrinterSettings.DefaultPageSettings.Margins.Right - Printer.PrinterSettings.DefaultPageSettings.Margins.Left, _
                                              Printer.PrinterSettings.DefaultPageSettings.Margins.Bottom - Printer.PrinterSettings.DefaultPageSettings.Margins.Top)

       Dim xPos As Integer = Printer.PrinterSettings.DefaultPageSettings.Margins.Left
       Dim yPos As Integer = Printer.PrinterSettings.DefaultPageSettings.Margins.Top

       For i = 0 To RTB.Text.Length
           RTB.Select(i, 1)
           Dim sChar As Char = RTB.SelectedText
           Dim cColor As Color = RTB.SelectionColor
           Dim fFont As Font = RTB.SelectionFont
           Dim iHeight As Integer = fFont.Height
           Dim theSize As New SizeF(e.Graphics.MeasureString(theWord, fFont))
           If Asc(sChar) = 10 Then
               e.Graphics.DrawString(theWord, fFont, New SolidBrush(cColor), xPos, yPos)
               xPos += Int(theSize.Width)
               theWord = ""
               xPos = Printer.PrinterSettings.DefaultPageSettings.Margins.Left
               yPos += iHeight + 3
           ElseIf Not Asc(sChar) = 32 Or Asc(sChar) = 10 Or Asc(sChar) = 8 Then
               theWord = theWord & sChar
           Else
               If (xPos + theSize.Width > (Printer.PrinterSettings.DefaultPageSettings.PaperSize.Width - 75)) Then
                   xPos = Printer.PrinterSettings.DefaultPageSettings.Margins.Left
                   yPos += iHeight + 3
               End If
               e.Graphics.DrawString(theWord, fFont, New SolidBrush(cColor), xPos, yPos)
               xPos += Int(theSize.Width)
               theWord = ""
           End If
       Next
   End Sub

 

:)

 

Needs support for multipage

Code today gone tomorrow!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...