
Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Thanks for the response, Jon. As I was posting a snippet of the code, I noticed a problem with the code. Correcting did prove that the trim was working.
So, let me ask a slightly different questions:
I'm trying to, in essence, create a table of data (6 columns) where the text in each column starts in the same character position on the page. Below is part of the code. My problem is that even when I subtract the desired character position from the accumulated length of the preceding text, I can't get column 3 (for example) to line up. Note, the length of ODITNO never exceeds 30.
....
line = line & ODITNO & Microsoft.VisualBasic.Space(50 - Microsoft.VisualBasic.Len(ODITNO)) & ItemDescription
The ODITNO value is column 2 and it's length varies, so the beginning of the text for column 3 (ItemDescription) varies as well.
Remember, I doing this for a PrintDocument, used in the following:
document = header & line
ev.Graphics.DrawString(document, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
I'm sure there just something wrong with my logic. Any suggestions?
Thanks.
Ross
>> Can anyone explain to me why Microsoft.VisualBasic.RTrim or
>> Microsoft.VisualBasic.Trim do not remove the trailing blank spaces in a word
[quoted text clipped - 10 lines]
> See http://www.pobox.com/~skeet/csharp/complete.html for details of
> what I mean by that.
Jon Skeet [C# MVP] - 18 Mar 2008 19:19 GMT
> Thanks for the response, Jon. As I was posting a snippet of the code,
> I noticed a problem with the code. Correcting did prove that the trim
> was working.
Let me guess - you were calling RTrim, but assuming it would trim the
string itself rather than returning a trimmed string?
> So, let me ask a slightly different questions:
>
[quoted text clipped - 18 lines]
>
> I'm sure there just something wrong with my logic. Any suggestions?
I can't say I'm familiar with all of this - but is it a monospaced
font?
Does the position of column 3 vary in a predictable way? Does column 2
line up?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Ross Culver - 18 Mar 2008 19:27 GMT
Column 2 lines up, but that's because the value in column 1 can only be
either 1 or 2 characters long, so the 'if' coding is simple. Column 3's
data doesn't vary predictably. It can range from 2 to 30 characters. The
font is defined in the document settings as Arial 9.
Thanks for your time.
>> Thanks for the response, Jon. As I was posting a snippet of the code,
>> I noticed a problem with the code. Correcting did prove that the trim
[quoted text clipped - 31 lines]
> Does the position of column 3 vary in a predictable way? Does column 2
> line up?
Jon Skeet [C# MVP] - 18 Mar 2008 19:36 GMT
> Column 2 lines up, but that's because the value in column 1 can only be
> either 1 or 2 characters long, so the 'if' coding is simple. Column 3's
> data doesn't vary predictably. It can range from 2 to 30 characters. The
> font is defined in the document settings as Arial 9.
Okay, that's the problem then - Arial is a proportional font. For
instance, "iiiii" will take up a lot less space than "MMMMM".
You'll either need to use a non-proportional font, or draw the
different columns using separate DrawString calls.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Ross Culver - 18 Mar 2008 19:42 GMT
Ok, I can use a different, non-proportional font. But I don't know how to
concatenate the drawstring calls. So, if I understand you, I can call as
many DrawString calls as I want in a single print; the trick is to format
each so they don't overlap. Is that correct?
Ross
>> Column 2 lines up, but that's because the value in column 1 can only be
>> either 1 or 2 characters long, so the 'if' coding is simple. Column 3's
[quoted text clipped - 7 lines]
> You'll either need to use a non-proportional font, or draw the
> different columns using separate DrawString calls.
Jon Skeet [C# MVP] - 18 Mar 2008 19:48 GMT
> Ok, I can use a different, non-proportional font.
That would probably be the simplest solution, yes.
> But I don't know how to
> concatenate the drawstring calls. So, if I understand you, I can call as
> many DrawString calls as I want in a single print; the trick is to format
> each so they don't overlap. Is that correct?
Sounds about right to me. You can call MeasureString with some
arbitrary "as wide as it will get" string to work out distances - or
hard code them, I guess.
Hopefully someone who's actually *done* some printing in .NET will
chime in at some point...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Ross Culver - 18 Mar 2008 19:33 GMT
By the way, I tried using Microsoft.VisualBasic.vbTab, but that didn't seem
to do anything, even when I concatenated 2 or 3 together.
Ross
>> Thanks for the response, Jon. As I was posting a snippet of the code,
>> I noticed a problem with the code. Correcting did prove that the trim
[quoted text clipped - 31 lines]
> Does the position of column 3 vary in a predictable way? Does column 2
> line up?