删除 TableLayoutPanel 中的 Row 会导致布局问题

我有一个 WinForms 应用程序,它有一个TableLayoutPanel; 这是定义代码:


tableLayoutPanel1 = new TableLayoutPanel();

tableLayoutPanel1.Dock = DockStyle.Fill;

tableLayoutPanel1.AutoScroll = true;


tableLayoutPanel1.RowCount = users.Count + 1;

tableLayoutPanel1.ColumnCount = 1;

tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;

tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));


foreach (String user in users)

{

    tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 600F));

}

tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 600F));


int index = 0;

foreach (String user in users)

{

    AddDockedControl(index, user);

    index++;

}

AddDockedControl(index, null);


panel1.Controls.Add(tableLayoutPanel1);


private void AddDockedControl(int row, String userName)

{

    AccountRowUC newUser = new AccountRowUC(this, userName, row);

    newUser.BorderStyle = BorderStyle.FixedSingle;

    newUser.Dock = DockStyle.Top;

    tableLayoutPanel1.Controls.Add(newUser, 0, row);

}

现在,当我想删除其中一行时,我正在使用以下代码:


public void RemoveRowAtIndex(int index)

{

    if (index >= tableLayoutPanel1.RowCount)

        return;


    // delete all controls of row that we want to delete

    for (int i = 0; i < tableLayoutPanel1.ColumnCount; i++)

    {

        var control = tableLayoutPanel1.GetControlFromPosition(i, index);

        tableLayoutPanel1.Controls.Remove(control);

    }


    // move up row controls that comes after row we want to remove

    for (int i = index + 1; i < tableLayoutPanel1.RowCount; i++)

    {

        for (int j = 0; j < tableLayoutPanel1.ColumnCount; j++)

        {

            var control = tableLayoutPanel1.GetControlFromPosition(j, i);

            if (control != null)

                tableLayoutPanel1.SetRow(control, i - 1);

        }

    }


    // remove last row


    tableLayoutPanel1.RowStyles.RemoveAt(tableLayoutPanel1.RowCount - 1);

    //tableLayoutPanel1.RowStyles.RemoveAt(index);

    tableLayoutPanel1.RowCount--;

}

问题是当我删除一个 Row 时,表格底部会留下一个很大的空间:TableLayoutPanel 不会回收panel1.


繁星点点滴滴
浏览 99回答 1
1回答

Qyouu

基于评论中描述的布局的解决方案和之前发布的此答案:Center multiple rows of controls in a FlowLayoutPanel描述:(本文底部提供的测试表格的完整代码)创建一个新表单(这里,命名为frmTLPTest1)添加两个面板。一个用于承载一些按钮,另一个将是 TableLayoutPanel 的容器。将 Container 面板设置为AutoScroll = true,&nbsp;AutoSizeMode = AutoSizeMode.GrowAndShrink, 设置所有 Anchors (Left, Top, Right, Bottom)在 Container 面板中,放置一个新的 TableLayoutPanel:将其设置为AutoSize = true,&nbsp;AutoSizeMode = AutoSizeMode.GrowAndShrink,Dock = DockStyle.Top从 TableLayoutPanel 中删除所有行和列,除了每个行和列(不能全部删除)。将两者的尺寸设置为AutoSize。重要说明(也在链接答案中报告):在 Form 构造函数中,删除了其中一个 RowStyles。这很重要:TLP 将保留 2 个 RowStyle。一个应用于现有的 Row;第二种样式将应用于您添加的第一行:仅应用于第一个,而不应用于其他。如果不删除此样式,则会影响布局。用于向 TableLayoutPanel 添加行/从 TableLayoutPanel 中删除行的核心方法,使用 FlowLayoutPanel 作为 TLP Row 内容,最终也可以用作其他控件的容器。TlpAddRow(TableLayoutPanel tlp, bool addRowCount)方法:将新的 FlowLayoutPanel 添加到指定的 TableLayoutPanel 的 Cell 中,并在请求时添加新的 Row。由于设计器不允许删除所有行,因此第一行(FlowLayoutPanel) 不得增加行数:addRowCount参数将设置为false.private Control TlpAddRow(TableLayoutPanel tlp, bool addRowCount){&nbsp; &nbsp; var flp = new FlowLayoutPanel() {&nbsp; &nbsp; &nbsp; &nbsp; Anchor = AnchorStyles.Top | AnchorStyles.Bottom,&nbsp; &nbsp; &nbsp; &nbsp; AutoSize = true,&nbsp; &nbsp; &nbsp; &nbsp; AutoSizeMode = AutoSizeMode.GrowAndShrink,&nbsp; &nbsp; };&nbsp; &nbsp; tlp.SuspendLayout();&nbsp; &nbsp; if (addRowCount) tlp.RowCount += 1;&nbsp; &nbsp; tlp.Controls.Add(flp, 0, tlp.RowCount - 1);&nbsp; &nbsp; tlp.ResumeLayout(true);&nbsp; &nbsp; return flp;}TLPRemoveRow(TableLayoutPanel tlp, Control control)方法(重载):允许从指定的 TableLayoutPanel 中删除行。要删除的 Row 可以从用作 Row Container 的 Control 派生(此处为 FlowLayoutPanel,但它可以是 Panel、另一个 TableLayoutPanel 或其他一些类型的 Container 控件)。也可以通过直接指定 Row 索引来移除 Row。private void TLPRemoveRow(TableLayoutPanel tlp, Control control){&nbsp; &nbsp; int ctlRow = tlp.GetRow(control);&nbsp; &nbsp; TLPRemoveRow(tlp, ctlRow);}private void TLPRemoveRow(TableLayoutPanel tlp, int row){&nbsp; &nbsp; if (row < tlp.RowCount - 1) {&nbsp; &nbsp; &nbsp; &nbsp; for (int i = row; i < tlp.RowCount - 1; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tlp.SetRow(tlp.GetControlFromPosition(0, i + 1), i);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; tlp.RowCount -= 1;}此布局的视觉结果:https://i.stack.imgur.com/hJs0i.gif 由于通过测试而不是解释更容易理解它的工作原理,因此这是表单的完整布局:测试表格( frmTLPTest1):using System.Drawing;using System.Linq;using System.Windows.Forms;public partial class frmTLPTest1 : Form{&nbsp; &nbsp; public frmTLPTest1()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent();&nbsp; &nbsp; &nbsp; &nbsp; tlp1.RowStyles.RemoveAt(1);&nbsp; &nbsp; }&nbsp; &nbsp; protected override void OnLoad(EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; base.OnLoad(e);&nbsp; &nbsp; &nbsp; &nbsp; TlpAddRow(tlp1, false);&nbsp; &nbsp; }&nbsp; &nbsp; Random rnd = new Random();&nbsp; &nbsp; Size[] sizes = new Size[] { new Size(75, 75), new Size(100, 100), new Size(125, 125)};&nbsp; &nbsp; Color[] colors = new Color[] { Color.Red, Color.LightGreen, Color.YellowGreen, Color.SteelBlue };&nbsp; &nbsp; Control selectedObject = null;&nbsp; &nbsp; Control selectedParent = null;&nbsp; &nbsp; private void btnAddControl_Click(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Size size = new Size(125, 125);&nbsp; &nbsp; &nbsp; &nbsp; if (chkRandom.Checked) size = sizes[rnd.Next(sizes.Length)];&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; var pBox = new PictureBox() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Anchor = AnchorStyles.None,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BackColor = colors[rnd.Next(colors.Length)],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MinimumSize = size,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size = size&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; bool drawborder = false;&nbsp; &nbsp; &nbsp; &nbsp; pBox.MouseEnter += (s, evt) => { drawborder = true;&nbsp; pBox.Invalidate(); };&nbsp; &nbsp; &nbsp; &nbsp; pBox.MouseLeave += (s, evt) => { drawborder = false; pBox.Invalidate(); };&nbsp; &nbsp; &nbsp; &nbsp; pBox.MouseDown += (s, evt) => { selectedParent = pBox.Parent;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedObject = pBox;&nbsp; pBox.Invalidate();&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; pBox.Paint += (s, evt) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (drawborder) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ControlPaint.DrawBorder(evt.Graphics, pBox.ClientRectangle,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color.White, ButtonBorderStyle.Solid);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; if (tlp1.RowCount == 0) TlpAddRow(tlp1, true);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; var ctl = tlp1.GetControlFromPosition(0, tlp1.RowCount - 1);&nbsp; &nbsp; &nbsp; &nbsp; int overallWith = 0;&nbsp; &nbsp; &nbsp; &nbsp; if (ctl.Controls?.Count > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; overallWith = ctl.Controls.OfType<Control>().Sum(c => c.Width + c.Margin.Left + c.Margin.Right);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; overallWith += ctl.Margin.Right + ctl.Margin.Left + pBox.Size.Width + pBox.Margin.Left + pBox.Margin.Right;&nbsp; &nbsp; &nbsp; &nbsp; if (overallWith >= tlp1.Width) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl = TlpAddRow(tlp1, true);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; ctl.Controls.Add(pBox);&nbsp; &nbsp; }&nbsp; &nbsp; private void btnRemoveRow_Click(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (selectedParent is null) return;&nbsp; &nbsp; &nbsp; &nbsp; if (selectedParent.Controls.Count > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i == selectedParent.Controls.Count - 1; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedParent.Controls[i].Dispose();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; TLPRemoveRow(tlp1, selectedParent);&nbsp; &nbsp; &nbsp; &nbsp; selectedParent.Dispose();&nbsp; &nbsp; }&nbsp; &nbsp; private void btnRemoveControl_Click(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (selectedObject is null) return;&nbsp; &nbsp; &nbsp; &nbsp; Control parent = selectedObject.Parent;&nbsp; &nbsp; &nbsp; &nbsp; selectedObject.Dispose();&nbsp; &nbsp; &nbsp; &nbsp; if (parent?.Controls.Count == 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TLPRemoveRow(tlp1, parent);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent.Dispose();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; private Control TlpAddRow(TableLayoutPanel tlp, bool addRowCount)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; var flp = new FlowLayoutPanel() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Anchor = AnchorStyles.Top | AnchorStyles.Bottom,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AutoSize = true,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AutoSizeMode = AutoSizeMode.GrowAndShrink,&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; tlp.SuspendLayout();&nbsp; &nbsp; &nbsp; &nbsp; if (addRowCount) tlp.RowCount += 1;&nbsp; &nbsp; &nbsp; &nbsp; tlp.Controls.Add(flp, 0, tlp.RowCount - 1);&nbsp; &nbsp; &nbsp; &nbsp; tlp.ResumeLayout(true);&nbsp; &nbsp; &nbsp; &nbsp; return flp;&nbsp; &nbsp; }&nbsp; &nbsp; private void TLPRemoveRow(TableLayoutPanel tlp, Control control)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; int ctlRow = tlp.GetRow(control);&nbsp; &nbsp; &nbsp; &nbsp; TLPRemoveRow(tlp, ctlRow);&nbsp; &nbsp; }&nbsp; &nbsp; private void TLPRemoveRow(TableLayoutPanel tlp, int row)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (row < tlp.RowCount - 1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = row; i < tlp.RowCount - 1; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tlp.SetRow(tlp.GetControlFromPosition(0, i + 1), i);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; tlp.RowCount -= 1;&nbsp; &nbsp; }}测试表单设计器:partial class frmTLPTest1{&nbsp; &nbsp; private System.ComponentModel.IContainer components = null;&nbsp; &nbsp; protected override void Dispose(bool disposing)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (disposing && (components != null)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; components.Dispose();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; base.Dispose(disposing);&nbsp; &nbsp; }&nbsp; &nbsp; private void InitializeComponent()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar = new System.Windows.Forms.Panel();&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow = new System.Windows.Forms.Button();&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom = new System.Windows.Forms.CheckBox();&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl = new System.Windows.Forms.Button();&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl = new System.Windows.Forms.Button();&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground = new System.Windows.Forms.Panel();&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1 = new System.Windows.Forms.TableLayoutPanel();&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.SuspendLayout();&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.SuspendLayout();&nbsp; &nbsp; &nbsp; &nbsp; this.SuspendLayout();&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // panToolbar&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.BackColor = System.Drawing.Color.DarkOliveGreen;&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Controls.Add(this.btnRemoveRow);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Controls.Add(this.chkRandom);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Controls.Add(this.btnRemoveControl);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Controls.Add(this.btnAddControl);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Dock = System.Windows.Forms.DockStyle.Bottom;&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Location = new System.Drawing.Point(0, 359);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Name = "panToolbar";&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.Size = new System.Drawing.Size(552, 55);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.TabIndex = 2;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // btnRemoveRow&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.FlatStyle = System.Windows.Forms.FlatStyle.Flat;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.ForeColor = System.Drawing.Color.White;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.Location = new System.Drawing.Point(261, 11);&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.Name = "btnRemoveRow";&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.Size = new System.Drawing.Size(119, 34);&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.TabIndex = 4;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.Text = "Remove Row";&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.UseVisualStyleBackColor = false;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveRow.Click += new System.EventHandler(this.btnRemoveRow_Click);&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // chkRandom&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.AutoSize = true;&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.ForeColor = System.Drawing.Color.White;&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.Location = new System.Drawing.Point(446, 20);&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.Name = "chkRandom";&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.Size = new System.Drawing.Size(94, 19);&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.TabIndex = 3;&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.Text = "Random Size";&nbsp; &nbsp; &nbsp; &nbsp; this.chkRandom.UseVisualStyleBackColor = true;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // btnRemoveControl&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.FlatStyle = System.Windows.Forms.FlatStyle.Flat;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.ForeColor = System.Drawing.Color.White;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.Location = new System.Drawing.Point(136, 11);&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.Name = "btnRemoveControl";&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.Size = new System.Drawing.Size(119, 34);&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.TabIndex = 2;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.Text = "Remove Control";&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.UseVisualStyleBackColor = false;&nbsp; &nbsp; &nbsp; &nbsp; this.btnRemoveControl.Click += new System.EventHandler(this.btnRemoveControl_Click);&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // btnAddControl&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.FlatStyle = System.Windows.Forms.FlatStyle.Flat;&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.ForeColor = System.Drawing.Color.White;&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.Location = new System.Drawing.Point(11, 11);&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.Name = "btnAddControl";&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.Size = new System.Drawing.Size(119, 34);&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.TabIndex = 0;&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.Text = "Add Control";&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.UseVisualStyleBackColor = false;&nbsp; &nbsp; &nbsp; &nbsp; this.btnAddControl.Click += new System.EventHandler(this.btnAddControl_Click);&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // panBackground&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; | System.Windows.Forms.AnchorStyles.Left)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; | System.Windows.Forms.AnchorStyles.Right)));&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.AutoScroll = true;&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.Controls.Add(this.tlp1);&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.Location = new System.Drawing.Point(0, 0);&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.Name = "panBackground";&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.Size = new System.Drawing.Size(552, 360);&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.TabIndex = 3;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // tlp1&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.AutoSize = true;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.ColumnCount = 1;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.Dock = System.Windows.Forms.DockStyle.Top;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.Location = new System.Drawing.Point(0, 0);&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.Name = "tlp1";&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.RowCount = 1;&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.RowStyles.Add(new System.Windows.Forms.RowStyle());&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 1F));&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.Size = new System.Drawing.Size(552, 2);&nbsp; &nbsp; &nbsp; &nbsp; this.tlp1.TabIndex = 4;&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // frmTLPTest1&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);&nbsp; &nbsp; &nbsp; &nbsp; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;&nbsp; &nbsp; &nbsp; &nbsp; this.ClientSize = new System.Drawing.Size(552, 414);&nbsp; &nbsp; &nbsp; &nbsp; this.Controls.Add(this.panBackground);&nbsp; &nbsp; &nbsp; &nbsp; this.Controls.Add(this.panToolbar);&nbsp; &nbsp; &nbsp; &nbsp; this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));&nbsp; &nbsp; &nbsp; &nbsp; this.Name = "frmTLPTest1";&nbsp; &nbsp; &nbsp; &nbsp; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;&nbsp; &nbsp; &nbsp; &nbsp; this.Text = "frmTLPTest1";&nbsp; &nbsp; &nbsp; &nbsp; this.Load += new System.EventHandler(this.SOfrmTest1_Load);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.ResumeLayout(false);&nbsp; &nbsp; &nbsp; &nbsp; this.panToolbar.PerformLayout();&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.ResumeLayout(false);&nbsp; &nbsp; &nbsp; &nbsp; this.panBackground.PerformLayout();&nbsp; &nbsp; &nbsp; &nbsp; this.ResumeLayout(false);&nbsp; &nbsp; }&nbsp; &nbsp; private System.Windows.Forms.Panel panToolbar;&nbsp; &nbsp; private System.Windows.Forms.Button btnAddControl;&nbsp; &nbsp; private System.Windows.Forms.Button btnRemoveControl;&nbsp; &nbsp; private System.Windows.Forms.CheckBox chkRandom;&nbsp; &nbsp; private System.Windows.Forms.Panel panBackground;&nbsp; &nbsp; private System.Windows.Forms.TableLayoutPanel tlp1;&nbsp; &nbsp; private System.Windows.Forms.Button btnRemoveRow;}
打开App,查看更多内容
随时随地看视频慕课网APP