本文介绍了如何自动调整TableLayoutPanel的内容以便在C#中使用Form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy!



请帮我解决以下问题:



我无法制作我的TableLAyoutPanel自动调整以填充表单中的内容。



请参阅下面我的源代码



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

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));
            }
        }

推荐答案

这篇关于如何自动调整TableLayoutPanel的内容以便在C#中使用Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 14:40