Hello guys. I have a simple 2D array with 9 elements, and i loop through them and I'm trying to write them on a form. But they aren't aligned properly. I tried with PadLeft but it didn't work. Here is my code:
int[][] array = { new int[3] {-1, 2, 3}, new int[3] {4, 53, 6}, new int[3] {7, 8, -9} }; public Form1() { InitializeComponent(); Load += new EventHandler(Form1_Load); } void Form1_Load(object sender, EventArgs e) { string myString; int width = 10, height = 10; int maxLenght = array[0][0]; Label[] labels = new Label[3]; for (int i = 0; i < 3; ++i) { myString = string.Empty; for (int j = 0; j < 3; ++j) { myString += array[i][j].ToString() + " "; } labels[i] = new Label(); labels[i].AutoSize = true; labels[i].Location = new Point(width, height += 20); labels[i].Text = myString.PadLeft(5); this.Controls.Add(labels[i]); } }
and here is my result: http://img23.imageshack.us/img23/2306/alignedy.png
I noticed if all elements has the same lenght, they are aligned correctly.
Thanks!