-
September 16th, 2011, 06:30 AM
#1
[RESOLVED] Printing Tab Character
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)
-
September 16th, 2011, 07:07 AM
#2
Re: Printing Tab Character
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?
Always use [code][/code] tags when posting code.
-
September 16th, 2011, 07:51 AM
#3
Re: Printing Tab Character
Originally Posted by DataMiser
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
-
September 16th, 2011, 09:54 AM
#4
Re: Printing Tab Character
You need to use the StringFormat.SetTabStops Method:
http://msdn.microsoft.com/en-us/libr...ttabstops.aspx
-
September 19th, 2011, 06:02 AM
#5
Re: Printing Tab Character
Originally Posted by Peter_B
Thanks so much for that, Peter, exactly what I needed. Waited for weeks on another forum with over 50 reads and zero replies! Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|