Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Label matrix align

$
0
0
Hello guys. I have an 2D array ( n x m ) with int values. Each line I transform it into a string, and I'm trying to align them correctly. Everything it's ok when all elements has same size ( 1, 5, 3; 22, 31, 44; etc. ), but when one element has the lenght not equal with the rest of elements, the labels aren't aligned correctly. Look what I mean:
This is good: http://img839.imageshack.us/img839/4120/goodzj.png
This is bad: http://img267.imageshack.us/img267/9770/badz.png

And this is my code:
n = GV.a[0].GetUpperBound(0) + 1;
            m = GV.a[0].GetUpperBound(1) + 1;

            label1.Location = new Point(this.Width / 2 - label1.Text.Length * 4, label1.Location.Y);

            int width  = this.Width / 2 + m * 8;
            int height = label1.Location.Y + 20;
            string text, space = "     ";

            for (int i = 0; i < n; ++i)
            {
                text = string.Empty;
                for (int j = 0; j < m; ++j)
                {
                    text += GV.a[type][i, j].ToString() + space;
                    text = text.PadRight(10 - (GV.a[type][i, j].ToString().Length * 2));
                }
                Label val = new Label();
                val.AutoSize = true;
                val.Location = new Point(width / 2, height);
                val.Text = text;
                this.Controls.Add(val);

                height += 20;
            }

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>