Lining up data under titles

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

I'm trying to code something so that I can line up product information
under it's titles like so:

Product#: Qty Price Product Name
6666 1 7.5 Product2

Using the \t code in C# doesn't work because where it tabs to for each
line isn't always the same.

So I tried to pad spaces to each section and line them up that way.
So I would add 5 spaces to "Product#:" which brought it to 15, and so
on with the rest of the titles.

I then do the same thing with each line underneath the titles, adding
spaces to the product value until I get to 15 and so on with the
others.

So everything should line up I would think. But it doesn't, things
still are off ever so slightly.

Is there another way to code this that I'm just not seeing?
 
Doug said:
I'm trying to code something so that I can line up product information
under it's titles like so:

Product#: Qty Price Product Name
6666 1 7.5 Product2

Using the \t code in C# doesn't work because where it tabs to for each
line isn't always the same.

So I tried to pad spaces to each section and line them up that way.
So I would add 5 spaces to "Product#:" which brought it to 15, and so
on with the rest of the titles.

I then do the same thing with each line underneath the titles, adding
spaces to the product value until I get to 15 and so on with the
others.

So everything should line up I would think. But it doesn't, things
still are off ever so slightly.

Is there another way to code this that I'm just not seeing?

What font are you using? If that's proportional (meaning the various
characters all have different sizes) then I think you will have to write
your own screenpainter.
Or you could use a fixed-width font ('Courier New' for example).

By the way, for those extra spaces you can use String.Format
to add spaces either to the left or to the right (you didn't specify
how you solved that..)


Hans Kesting
 
Hey there,
After I sent the first question I figured out the whole font thing
and we decided to go with Courier New which should alleviate some of
the issue. However, there's no guarantee that the email we send will
be recieved by the customer in Courier New because they can have their
email preferences set to receive it in any font they want. So I'm not
sure if that'll get me around the problem 100% completely. Do you
have any suggestions in that arena?

As far as how I'm adding the spaces, I ended up using PadRight.
 
Back
Top