首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TableLayoutPanel和AutoScroll

TableLayoutPanel和AutoScroll
EN

Stack Overflow用户
提问于 2011-02-09 03:18:34
回答 3查看 11.6K关注 0票数 2

我有一个可以动态添加行的TableLayoutPanel。

每行都有一个绝对大小。

我将AutoScroll设置为"true",但是当我添加超出TableLayoutPanel显示的行时,我看不到滚动。

这是设计器代码:

代码语言:javascript
复制
namespace WindowsFormsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // tableLayoutPanel1
            // 
            this.tableLayoutPanel1.AutoScroll = true;
            this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            this.tableLayoutPanel1.ColumnCount = 1;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Location = new System.Drawing.Point(24, 48);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 1;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(239, 163);
            this.tableLayoutPanel1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(24, 10);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(239, 28);
            this.button1.TabIndex = 1;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.tableLayoutPanel1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
        private System.Windows.Forms.Button button1;
    }
}

下面是我添加行的方式:

代码语言:javascript
复制
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tableLayoutPanel1.RowCount++;
            tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30));
            Button b = new Button();
            tableLayoutPanel1.Controls.Add(b, 0, tableLayoutPanel1.RowCount - 1);

        }
    }
}

有人知道这是怎么回事吗?

谢谢:)

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-02-09 03:21:36

将AutoScroll属性设置为True。

确保设计器添加的默认行不会造成任何问题。让你的构造函数看起来像这样:

代码语言:javascript
复制
    public Form1() {
        InitializeComponent();
        tableLayoutPanel1.RowCount = 0;
        tableLayoutPanel1.RowStyles.Clear();
        tableLayoutPanel1.AutoScroll = true;
    }
票数 5
EN

Stack Overflow用户

发布于 2011-07-30 08:46:16

看起来你遗漏了tableLayoutPanel.AutoSize = true。

票数 2
EN

Stack Overflow用户

发布于 2017-10-18 05:18:41

试试下面这行,它可能对你有用:

代码语言:javascript
复制
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.Dock = DockStyle.Top;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4937291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档