简体   繁体   中英

How to change position of inherited items in an Inherited user control

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

From MSDN: Control.Anchor Property

Use the Anchor property to define how a control is automatically resized as its parent control is resized. Anchoring a control to its parent control ensures that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resized.

You can anchor a control to one or more edges of its container. For example, if you have a Form with a Button whose Anchor property value is set to Top and Bottom, the Button is stretched to maintain the anchored distance to the top and bottom edges of the Form as the Height of the Form is increased.

Set the Anchor property on all labels: For example:

label1.Anchor = AnchorStyles.Top | AnchorStyles.Left;

If you put your controls in a FlowLayoutPanel and set the following options:

AutoScroll = True
FlowDirection = TopDown
WrapContents = False

Then you should get panel that will grow and shrink as your controls are added or removed.

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM