首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含tableLayoutPanel的自动尺寸面板

包含tableLayoutPanel的自动尺寸面板
EN

Stack Overflow用户
提问于 2017-03-08 16:43:26
回答 1查看 765关注 0票数 0

我有一个包含面板的元素:

代码语言:javascript
复制
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tableLayoutPanel1.SetColumnSpan(this.panel1, 2);
this.panel1.Controls.Add(this.tableLayoutPanel2);
this.panel1.Location = new System.Drawing.Point(10, 10);
this.panel1.Margin = new System.Windows.Forms.Padding(10);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(264, 100);
this.panel1.TabIndex = 2;

此面板包含一个tableLayoutPanel。tableLayoutPanel有2行自动大小,包含标签/按钮:

代码语言:javascript
复制
this.tableLayoutPanel2.ColumnCount = 2;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.Controls.Add(this.button2, 1, 0);
this.tableLayoutPanel2.Controls.Add(this.button3, 1, 1);
this.tableLayoutPanel2.Controls.Add(this.label1, 0, 0);
this.tableLayoutPanel2.Controls.Add(this.label2, 0, 1);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.Size = new System.Drawing.Size(262, 98);
this.tableLayoutPanel2.TabIndex = 0;

行的高度大小是正确的。我希望面板自动设置他的高度(我将在执行过程中隐藏一些行)。实际上我有:

当我将autoSize = true设置为panel1时,我有:

我该怎么做才能拥有这个?

如果在执行期间添加/删除行,则必须更新面板大小。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-08 19:32:02

看看"Control.SetBoundsCore“能不能帮到你。您必须创建您自己的面板,然后使用它。

您的问题的原因似乎是下面的代码行。

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

https://stackoverflow.com/questions/42677034

复制
相关文章

相似问题

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