1

I am trying to align values. I wonder why this happen :

        string value = "";

        value += string.Format("{0,-10}", "value");
        value += string.Format("{0,5}", "value");

        value += Environment.NewLine;

        value += string.Format("{0,-8}", "val");
        value += string.Format("{0,7}", "value");

        Print(value);

If i check value before i "Print" it is correct. The result is:

value     value
val       value

As they should be, but when i print "value" to my printer then they get like this :

   value     value
   val     value

I really cant understand why it changes the string when i print the text?

I have tried to use "\t" but my printer dont seem to understand "\t" because the tabs isnt printed out.

Btw: this is just a test code so you could understand the problem that i am having with the real code.

syncis
  • 1,395
  • 4
  • 25
  • 43

2 Answers2

2

This could be caused by a font that uses different character widths. In non-fixed-width fonts, spaces are often narrower than letters and numbers, so it might seem that spaces are missing. Consider using Lucida Console or another fixed-width font.

agent-j
  • 27,335
  • 5
  • 52
  • 79
  • You mean i should change my font on the printer? – syncis Jun 23 '11 at 13:25
  • @syncis, that might work. It depends on how you are printing. Are you using something like a FlowDocument? If so, change the font on the document. – agent-j Jun 23 '11 at 13:31
2

your console uses fixed width fonts where your printer does not (at least by default). So spaces take up less space on your printer and your letters take up more or less space based on their actual width.

Bueller
  • 2,336
  • 17
  • 11