GetWindowPlacement/SetWindowPlacement not working in WinForms for high DPI

Posted by RandomEngy on Stack Overflow See other posts from Stack Overflow or by RandomEngy
Published on 2010-04-09T15:48:49Z Indexed on 2010/04/09 16:43 UTC
Read the original article Hit count: 638

Filed under:
|
|
|

I've got a legacy WinForms app and I want to save the window position and size across sessions. I've been using GetWindowPlacement and SetWindowPlacement during the FormClosing and Load events. The problem I'm getting is that at higher DPI settings (Such as Medium, size at 125%) the sizes keep inflating. I'll call SetWindowPlacement on it with a certain size, but when GetWindowPlacement is called, those numbers come back 25% bigger, even though the window was the same size all along. The same sort of problem exists when saving the size of a resizable element within the form.

Now this works fine if I create a new WinForms project: The size stays stable even when running at the higher DPI. I'm guessing there's some legacy setting in the bowels of the project or some arcane Form setting that's messing it up, but I can't find out where.

I've called IsProcessDPIAware on both projects and both are true. Does anyone know what might be causing this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about window-management