我正在尝试使用循环自动填充一些标签。
Point labelLocation = new Point(5, 15);
// e is an enum passed to the function
// box is a GroupBox passed to the function
foreach(var value in Enum.GetValues(e.GetType()))
{
Label workingLabel = new Label
{
AutoSize = true,
Location = labelLocation,
BorderStyle = BorderStyle.Fixed3D,
Text = value.ToString()
};
labelLocation = new Point(labelLocation.X, workingLabel.Location.Y + workingLabel.Height);
box.Controls.Add(workingLabel);
}无论是否设置了自动调整大小,高度始终返回23。因此,如果我将autosize设置为false,我看到的边框太大,但包装得很好。如果我将它设置为true,我会看到完美的边框,除了它们之间有很大的间隙。
边框似乎与控件的高度不同,我不确定如何调整它以使它们相同。
发布于 2017-12-16 01:01:02
在将标签添加到容器之前,AutoSize不会发生。因此,尝试将这两行代码从:
labelLocation = new Point(labelLocation.X, workingLabel.Location.Y + workingLabel.Height);
box.Controls.Add(workingLabel);至
box.Controls.Add(workingLabel);
labelLocation = new Point(labelLocation.X, workingLabel.Location.Y + workingLabel.Height);https://stackoverflow.com/questions/47836457
复制相似问题