Skip to content

Anchor.None incorrect behaviour #17

Closed

Description

@itg-assistant

Łukasz Struzik asked 2016-05-02 11:16:00 UTC

Anchor.None doesn't behave as expected - it should "center align" the control, moving it half the vector of container size change. Tested on Desktop with Panel added to it's Controls collection.

MSDN - AnchorStyles Enumeration:
(...) If a control has its Anchor property set to AnchorStyles.None, the control moves half of the distance that the container of the control is resized. For example, if a Button has its Anchor property set to AnchorStyles.None and the Form that the control is located on is resized by 20 pixels in either direction, the button will be moved 10 pixels in both directions.

Edit (2016-05-05): Attached simple project I had that issue with. Also, it demonstrates another, minor issue - when i click the "Login" button, the login/password textboxes are moves a pixel up and left, and return to original positions when i release the button.

Best regards

Łukasz Struzik
Software designer-developer
COIG SA

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2016-05-02 12:41:11 UTC

    Hi Lukasz, thanks for your bug report.

    I could not yet reproduce it here. When I place a panel in a desktop window and set it Anchor “None”, the panel remains center aligned.
    Can you please either list the steps to reproduce the problem or provide us with a sample ?

    Thanks in advance,
    Frank

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2016-05-04 13:01:43 UTC

    Hi Lukasz,

    we can't reproduce. The behavior we see seems to be correct. When Anchor =  none the control keeps the same proportional distance, as defined in the msdn specs.

    can you please verify again and/or send the test you are using and what is the expected behavior?

    Best,

    Luca

  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Łukasz Struzik answered 2016-05-05 05:09:00 UTC

    I attached the sample project into original post.

    Best regards

    Łukasz Struzik
    Software designer-developer
    COIG SA

  4. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2016-05-08 17:54:23 UTC

    Thanks Lukasz.

    This issue has been logged as WJ-7244. It´s fixed and included in the latest release.

  5. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2016-05-09 15:39:48 UTC

    Thank you Lukasz, It was a problem with the Desktop container. It's fixed now.

    BTW, in your sample the panel ends up to the bottom right (I don't know if it was intended). That's because the code sets the size of the Desktop to a small size and sets the Location of the panel to the bottom right. When the layout starts it will maintain the proportions.

    Also, I noticed that the initialization code is written by hand in the constructor. It's a lot better if you move it to InitializeComponent(), put a call in the constructor, and use the designer. Also, when adding controls to a container, it's better to use SuspendLayout() and ResumeLayout() on the container to prevent the container to perform the layout on every change.

    HTH

    Best,

    Luca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions