Using the anchor property with dynamically added controls

I add text fields to the form dynamically at runtime. Everything works fine, i.e. text fields are aligned, anchored and automatically resized until the form is maximized. When maximizing the form, text fields are added to the same place, while the form is not maximized. This causes misalignment of the text fields.

How can I guarantee that all text fields are in the same place and have the same size while the window state is normal and maximized?

EDIT:

Btw I am using C #

EDIT:

Would the flowlayout panel be useful?

+3
source share
2 answers

This is a pretty old question, but maybe I can answer it.

After reading all your comments, I think I can summarize your problem:

  • You have a form with a specific size and adding some controls at runtime in a specific place with binding to binding Top | Right.
  • If you just display the form and let the controls appear, everything works fine
  • If you maximize your form (or change its size), your controls will no longer appear in the right place.

To get rid of this problem, you can try several different approaches:

- ( ). , . , (, ), .

  • .
  • (), .

, Top | Right, Top | Left. control.location.x . Width . . ( Top ). Bottom | Right, control.location.y form.height.

, Top | Bottom Left | Right, .; -)

, : :

  • , Form.Visible false
  • ,
  • .
+2

Anchor , , . , , , .

, , Panel. X Y , , .

0

Source: https://habr.com/ru/post/1707559/


All Articles