I have a form application in C#. When I change the monitor's DPI, all the controls move.
I used the code this.AutoScaleMode = AutoScaleMode.Dpi
, but it didn't avoid the problem.
Does anyone have an idea?
EDIT: As of .NET 4.7, windows forms has improved support for High DPI. Read more about it on docs.microsoft.com It only works for Win 10 Creators Update and higher though, so it might not be feasible to use this yet depending on your user base.
Difficult, but not impossible. Your best option is to move to WPF of course, but that might not be feasible.
I've spent A LOT of time with this problem. Here are some rules/guidelines to make it work correctly without a FlowLayoutPanel or TableLayoutPanel:
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); // for design in 96 DPI
I guarantee that if you follow these guidelines you will be ok, even when you have placed controls with specific anchors and don't use a flowpanel. We have an app built this way deployed on hundreds of machines with different DPI setups and we no longer have any complaints. All forms/containers/grids/buttons/textfield etc sizes are scaled correctly as is the font. Images work too, but they tend to get a little pixellated at high DPI.
EDIT: This link has a lot of good info, especially if you choose to use AutoScaleMode.DPI: link to related stackoverflow question