I can't find a suitable answer to this issue anywhere, including on this forum. SOmeone raised the dame question (Nov '10) but no answer so don't know if solution exists. Plenty of replies to 'replace the tab with spaces' but that does not align the text correctly. It can't be that hard, can it?
I'm printing a textbox which prints correctly except the tab chars are missing. So instead of:
123 456
I get:
123456
As mentioned replacing tabs with spaces is not suitable. What trick am i missing?
(VB.Net 2010)
When you say printing a textbox do you mean sending the data from a textbox to the printer or are you talking about something else?
Yes, sorry I can se the ambiguity in my question. I'm printing the textbox contents:
Private Sub prtDoc_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles prtDoc.BeginPrint
StringToPrint = Me.txtBody.Text
End Sub
Private Sub prtDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prtDoc.PrintPage
Dim numChars%, numLines%
Dim stringForPage$
Dim strFormat As New StringFormat()
Dim PrintFont As Font = Me.txtBody.Font
'Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
'Dim sizeMeasure As New SizeF(e.MarginBounds.Width, e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))
Dim rectDraw As New RectangleF(50, 100, 727, 969)
Dim sizeMeasure As New SizeF(727, 969 - PrintFont.GetHeight(e.Graphics))
'--------------------------
strFormat.Trimming = StringTrimming.Word
e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)
stringForPage = StringToPrint.Substring(0, numChars)
e.Graphics.DrawString(stringForPage, PrintFont, Brushes.Black, rectDraw, strFormat)
If numChars < StringToPrint.Length Then
StringToPrint = StringToPrint.Substring(numChars)
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
Bookmarks