Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Control array in a TableLayoutPanel has non-intuitive indexing

$
0
0

When you add controls to a TableLayoutPanel they appear starting at the top left and progressing to the right then the same for the row below the top and so on. So, why is the controls array indexed in the reverse order?

For example, I have a Noughts & Crosses grid - a 3x3 TableLayoutPanel (tlpNoughtsAndCrosses) with 9 large labels with large fonts added (at design time, not run time) - and this code:

            int iIndex;

            for (iIndex = 0; iIndex < 9; iIndex++)
            {
                tlpNoughtsAndCrosses.Controls[iIndex].Text=Convert.ToString(iIndex);
            }

produces the following, which I think is non-intuitive and a bit annoying.

TableLayoutPanel anomaly


Viewing all articles
Browse latest Browse all 12583

Trending Articles



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