Click here to Skip to main content
15,894,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hy!

Please help me with the following:

I can t make my TableLAyoutPanel to autoresize in order to fill the Form with the content.

See bellow my source code

C#
public Form1()
        {
            InitializeComponent();
            //AssignIconsToSquares();
            LoadGame(16,16);

        }

        private void LoadGame(int rows, int cols)
        {
            TableLayoutPanel table = new TableLayoutPanel();
            table.Dock = DockStyle.Fill;
            table.ColumnCount = cols;
            table.RowCount = rows;
            table.BackColor = Color.CornflowerBlue;
            for (int i = 0; i < rows; i++)
            {

                for (int j = 0; j < cols; j++)
                {
                    Label label = new Label();
                    label.Dock = DockStyle.Fill;
                    label.Name = "label" + i + "" + j;
                    label.Text = "c";
                    label.BorderStyle = BorderStyle.Fixed3D;
                    
                    table.Controls.Add(label, i, j);
                    table.AutoSize = true;
                    

                    
                }
            }
            this.Controls.Add(table);
            this.AutoScroll = true;
            this.HorizontalScroll.Enabled = true;
            this.VerticalScroll.Enabled = true;

            this.AutoSize = true;
           // this.HorizontalScroll

            table.RowStyles.Clear();

            for (int i = 0; i < rows; i++)
            {
                table.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            }

            table.ColumnStyles.Clear();

            for (int j = 0; j < cols; j++)
            {
                table.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            }
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900