5

I have used a user control as a base class (let's call it BaseUC) with 3 labels (in 3 lines) on it (they are set as protected).

And there is another user control that inherits from it (InheritedUC). I have added two more labels in InheritedUC, which are positioned between the base's labels (so there are 5 lines).

Everything is fine is Visiual Studio's design UI view. But when I run the application, labels on BaseUC overlap with the ones in InheritedUC and I can't see the ones on the inherited control.

Any ideas to fix this? Thank you very much

4

2 回答 2

1

来自 MSDN:Control.Anchor 属性

使用 Anchor 属性可以定义控件在调整其父控件大小时如何自动调整大小。将控件锚定到其父控件可确保在调整父控件大小时,锚定边缘相对于父控件的边缘保持在相同位置。

您可以将控件锚定到其容器的一个或多个边缘。例如,如果您有一个带有 Anchor 属性值设置为 Top 和 Bottom 的 Button 的 Form,当 Form 的高度增加时,Button 会被拉伸以保持到 Form 的顶部和底部边缘的锚定距离。

在所有标签上设置 Anchor 属性:例如:

label1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
于 2012-11-18T11:37:11.943 回答
1

如果您将控件放在 a 中FlowLayoutPanel并设置以下选项:

AutoScroll = True
FlowDirection = TopDown
WrapContents = False

然后你应该得到面板,它会随着你的控件的添加或删除而增长和缩小。

资源

于 2012-11-18T11:38:32.090 回答