So I have recently come across string.Format("{0, x}", "Word") for aligning strings, with demonstration code that works fine in the CMD.

Does this also function correctly when pumping text to a label? I am finding that it does not behave as expected and instead misaligns the text.

Using an example I nicked off a site

Console.WriteLine("First Name | Last Name  |   Age");
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Bill", "Gates", 51));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Edna", "Parker", 114));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Johnny", "Depp", 44));

Is shown to work fine in console however if you look at it within debugging or on a label its completely misaligned.

Are there any alternatives short of using /t to align or building everything up with strings, pad them and then append them onto the string builder I am using?

and Prit takes the gold star once again... now to find a fixed width font that looks pretty...

Good shout, it's Courier New though for monospacing

Edited 1 Year Ago by Mike Askew

This question has already been answered. Start a new discussion instead.