ispiro
ispiro

Reputation: 27713

UserControl Dock/Anchor not working

Here's a complete simple case:

  1. I created a UserControl. And added a Button on it Anchored top-right.
  2. I Dock.Filled the UserControl in Form1.

The Button is not in the correct place when executing (though it is in the Designer).

Screenshots:

UserControl Designer:

enter image description here

Form Designer:

enter image description here

Executing:

enter image description here

Executing, resized. As you can see, that doesn't help:

enter image description here

I tried changing my computer's text size from 125% to 100% but that didn't help either. Windows 10, VS 2017, .Net 4.7.1. I also tried setting the UserControl's Dock in its Load and ParentChanged event handlers, and its constructor. No change.

So how do I get the button to stay anchored?

EDIT (it seems to be somehow related to text size being different than 100%)

After a lot of fiddling I see now that after I change to 100% size text (In the Settings app under System-Display. Including logging off and on), clean and rebuild the solution, and then change back to 125% it works for some time. I can't find the exact limit for that.

Upvotes: 1

Views: 780

Answers (1)

Tanya Solyanik
Tanya Solyanik

Reputation: 181

@ispiro, could you please try to disable DPI awareness on your VisualStudio process and see if it helps. Here is a blog post that specifies the registry key to set: https://code4ward.net/2016/11/29/visual-studio-winforms-designer-on-highdpi/

Upvotes: 1

Related Questions