[SOLVED] Anchor.None incorrect behaviour

Answered Closed
0
0

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

Attachment
  • Frank (ITG)
    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
  • You must to post comments
Best Answer
0
0

Thanks Lukasz.

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

  • You must to post comments
0
0

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

 

  • You must to post comments
0
0

I attached the sample project into original post.

Best regards

Łukasz Struzik
Software designer-developer
COIG SA

  • You must to post comments
0
0

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

  • You must to post comments
Showing 4 results