Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 945
Yalda Avatar asked Nov 03 '22 11:11

Yalda


2 Answers

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;
like image 156
NET3 Avatar answered Nov 12 '22 14:11

NET3


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

like image 27
ChrisF Avatar answered Nov 12 '22 15:11

ChrisF