C# TableLayoutPanel和AutoScroll
我有一个TableLayoutPanel,可以动态地向其中添加行。 每行都有一个绝对大小。 我将AutoScroll设置为true,但是当我添加从TableLayoutPanel的显示中消失的行时,我看不到滚动 这是设计器代码:C# TableLayoutPanel和AutoScroll,c#,tablelayoutpanel,autoscroll,C#,Tablelayoutpanel,Autoscroll,我有一个TableLayoutPanel,可以动态地向其中添加行。 每行都有一个绝对大小。 我将AutoScroll设置为true,但是当我添加从TableLayoutPanel的显示中消失的行时,我看不到滚动 这是设计器代码: namespace WindowsFormsApplication1 { partial class Form1 { /// <summary> /// Required designer variable.
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;
}
}
有人知道发生了什么事吗?
谢谢:将AutoScroll属性设置为True 确保设计器添加的默认行不会引起任何问题。使您的构造函数如下所示:
public Form1() {
InitializeComponent();
tableLayoutPanel1.RowCount = 0;
tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.AutoScroll = true;
}
将AutoScroll属性设置为True 确保设计器添加的默认行不会引起任何问题。使您的构造函数如下所示:
public Form1() {
InitializeComponent();
tableLayoutPanel1.RowCount = 0;
tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.AutoScroll = true;
}
看起来您缺少tableLayoutPanel.AutoSize=true。看起来您缺少tableLayoutPanel.AutoSize=true。请尝试下一行,该行可能适合您:
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.Dock = DockStyle.Top;
请尝试下面这一行,它可能适合您:
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.Dock = DockStyle.Top;
谢谢你的补充评论。它帮助了我。事实上,如果您希望tablelayoutpanel在winform中滚动,则需要将autoscroll和autosize设置为true,并且-当然-确保tablelayoutpanel中的行的组合高度超出表单的高度。感谢您的补充意见。它帮助了我。事实上,如果希望tablelayoutpanel在winform中滚动,则需要将autoscroll和autosize都设置为true,并且-当然-确保tablelayoutpanel中的行的组合高度超出窗体的高度。