dotnet / dotnet/winforms

Form Layout (control size) bug with Anchor = Top | Bottom

Open
#6,041 19 comments 0 reactions 0 assignees View on GitHub
area-Anchor/Scaling
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

* .NET Core Version: all up to 6.0 rc2

* Have you experienced this same bug with .NET Framework?: Yes

**Problem description:**
Form, with any control and `Anchor = AnchorStyles.Top | AnchorStyles.Bottom`.
1. Remember form size and distance from bottom of this control to the bottom of the form.
2. Resize the form that this control become off-screen (if any part of the control still be visible - all work as expected).
3. Add any new control to the form (press `A` key in repro project below).
4. Resize form back to dimensions you remembered on step 1. And see that distance from bottom of the control to the bottom of the form is changed.

https://user-images.githubusercontent.com/17767561/138507989-b39e3f65-96b3-4385-abbc-8f2fa42f2a42.mp4

**Expected behavior:**
Distance from bottom of the control to the bottom of the form must be constant.

I think that the problem is that when new control added, new layout performs from scratch and therefore can't properly process the control with zero height and location outside of the current form dimensions. You can even emulate this in designer:

https://user-images.githubusercontent.com/17767561/138549216-991c7253-80c5-42ca-a049-4b66bc2a5a86.mp4

In the first time it's absolutely reasonable - no way to do this *right*. But I am wonder, if we already have properly align, is it possible not to reset it on `Layout`?

**Minimal repro:**
[FormLayoutBug.zip](https://github.com/dotnet/winforms/files/7400787/FormLayoutBug.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.