In the small test class below I have roughed out a wrapping of the string
using drawstring and measurestring. Note that without the to Math.Ceiling
uses that the drawstring still produces ellipsis. Is there anything I'm
missing here? I attempted to use a class from Duncan Mackenzie which seemed
to be doing the same thing as below but wrapping did not work. the text was
jumbled onto one line. Duncan changed the units to inches should I do the
same?
Public Class TestPrintDocument
Inherits System.Drawing.Printing.PrintDocument
Protected Overrides Sub OnPrintPage(ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
Dim h As Integer = 50
Dim w As Integer = 100
Dim rect As New RectangleF(50, 50, w, h)
Dim textof As String = "test the wrap of a string for print. does it wrap?"
Dim tfont As New Font("Arial", 10)
Dim sf As New StringFormat(StringFormatFlags.LineLimit)
Dim tsize As New SizeF(e.Graphics.MeasureString(textof, tfont))
Dim ratio As Single = Math.Ceiling(tsize.Width / w)
If ratio > 1 Then
rect.Height = (ratio) * Math.Ceiling(tsize.Height)
End If
sf.Alignment = StringAlignment.Near
sf.Trimming = StringTrimming.EllipsisCharacter
Dim i As Integer
For i = 0 To 2
e.Graphics.DrawString(textof, tfont, Brushes.Black, rect, sf)
rect.Y += rect.Height
Next
End Sub
End Class