【问题标题】:Controls have locked min. width or max size控件已锁定最小值。宽度或最大尺寸
【发布时间】:2014-05-28 18:31:49
【问题描述】:

我有一个带有 tableLayoutPanel 的表单。它有 1 列和 2 行,带有 2 个控件。一个标签和一个列表视图。在设计模式下,我无法将标签高度设置为大于 17。而 listView 我可以手动放大但不能缩小。控件尺寸仍然大于表单本身。所以要么控件被剪裁,要么我最终得到表单滚动条。那么为什么控件的自动大小大于表单呢?当我运行应用程序时,它们也不会缩小到 minSize。

// 
// labelTitle
// 
resources.ApplyResources(this.labelTitle, "labelTitle");
this.labelTitle.ForeColor = System.Drawing.Color.DeepSkyBlue;
this.labelTitle.Name = "labelTitle";
// 
// tableLayoutPanel
// 
resources.ApplyResources(this.tableLayoutPanel, "tableLayoutPanel");
this.tableLayoutPanel.Controls.Add(this.labelTitle, 0, 0);
this.tableLayoutPanel.Controls.Add(this.aListView, 0, 1);
this.tableLayoutPanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
this.tableLayoutPanel.Name = "tableLayoutPanel";
// 
// aListView
// 
resources.ApplyResources(this.aListView, "aListView");
this.aListView.AllowDrop = true;
this.aListView.BackColor = System.Drawing.SystemColors.Desktop;
this.aListView.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.aListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.aListView.LargeImageList = this.coverImageList;
this.aListView.MultiSelect = false;
this.aListView.Name = "aListView";
this.aListView.ShowGroups = false;
this.aListView.ShowItemToolTips = true;
this.aListView.TileSize = new System.Drawing.Size(200, 200);
this.aListView.UseCompatibleStateImageBehavior = false;
this.aListView.View = System.Windows.Forms.View.Tile;
// 
// form
// 
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Desktop;
this.Controls.Add(this.tableLayoutPanel);
this.Name = "Form";
this.albumsContextMenu.ResumeLayout(false);
this.tableLayoutPanel.ResumeLayout(false);
this.ResumeLayout(false);

我没有停靠控件,而是锚定了它们。现在,如果我先从顶部控件开始,我可以在设计模式下更改它们的大小。

【问题讨论】:

  • 将表单设置为 AutoSize 似乎是个坏主意 ;)

标签: c# winforms listview label tablelayoutpanel


【解决方案1】:

Label 默认有AutoSize = true,它会根据内容调整控件大小并忽略您的手动设置。

在看到更改大小的效果之前,您必须禁用 AutoSize 属性。

label1.AutoSize = false;
label1.Height = 50;

(注意你可以先设置Height,但是在禁用AutoSize之前你是看不到效果的。)


对于第二个问题,您必须详细说明 “listView 只会增加大小”的意思

【讨论】:

  • 但是为什么我的 ListView Width 的垂直大小锁定在 aprox. 600?它的 MinSize.Width 为 400。我现在已将 Form 的 MinSize 设置得足够大,因此 ListView 不能比 Form 大。
猜你喜欢
  • 2018-11-08
  • 1970-01-01
  • 1970-01-01
  • 2011-12-12
  • 1970-01-01
  • 2013-05-14
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
相关资源
最近更新 更多