【发布时间】: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