Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27212

VS 2012 [RESOLVED] Trying to make equal-sized cells in TableLayoutPanel

$
0
0
I'm trying to create a chessboard using a TableLayoutPanel of 64(8x8) cells, each cell to contain a PictureBox. I also want the chessboard to expand and contract as the user grows or shrinks the form. As you can see, I haven't got very far!
I thought the code below would at least be a start and would display the cells as 64 equal size squares but as you can see, it doesn't.

Code:

For i As Integer = 0 To TLP_Chessboard.ColumnCount - 1
            Dim tableColumnStyle As New ColumnStyle()
            tableColumnStyle.SizeType = SizeType.Percent
            tableColumnStyle.Width = CSng(100 / TLP_Chessboard.ColumnCount)
            TLP_Chessboard.ColumnStyles.Add(tableColumnStyle)
        Next


        TLP_Chessboard.RowStyles.Clear()
        For i As Integer = 0 To TLP_Chessboard.RowCount - 1
            Dim tableRowStyle As New RowStyle()
            tableRowStyle.SizeType = SizeType.Percent
            tableRowStyle.Height = CSng(100 / TLP_Chessboard.RowCount)
            TLP_Chessboard.ColumnStyles.Add(tableRowStyle)
        Next

Name:  TLP_1.PNG
Views: 67
Size:  1.9 KB

If, instead, I comment out this code and edit the rows and columns in the designer, setting each row and column to 12.5%, I get this:

Name:  TLP_2.PNG
Views: 56
Size:  2.1 KB

which is much closer to what I want but not close enough! Any ideas, please?
Attached Images
  

Viewing all articles
Browse latest Browse all 27212

Trending Articles



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