dummzeuch 1505 Posted August 28, 2022 Pressing Win+Left will dock the current window to the left edge of the current monitor. How can do that from code? I tried to set the form bounds, in particular Left to 0 but that leaves a gap of about 7 pixels. Setting it to -7 still leaves that gap. My Google fu has left me (again). All I can find is how to use the keyboard combination for that. Share this post Link to post
mvanrijnen 123 Posted August 28, 2022 following, same here, told the users to live with it for now 🙂 a solution would be nice. Share this post Link to post
Vandrovnik 214 Posted August 28, 2022 Setting form's Left works fine for me. I have autogenerated manifest, enabled runtime themes and "Per monitor v2" DPI Awarrness. Instead of setting Left to -7, I set it to minus (GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)), which is -8 on my PC. 1 Share this post Link to post
PeterBelow 238 Posted August 28, 2022 2 hours ago, dummzeuch said: Pressing Win+Left will dock the current window to the left edge of the current monitor. How can do that from code? I tried to set the form bounds, in particular Left to 0 but that leaves a gap of about 7 pixels. Setting it to -7 still leaves that gap. My Google fu has left me (again). All I can find is how to use the keyboard combination for that. Couldn't you just set the ScreenSnap property to true to allow the user to snap the form to a screen edge? Share this post Link to post
dummzeuch 1505 Posted August 28, 2022 2 minutes ago, PeterBelow said: Couldn't you just set the ScreenSnap property to true to allow the user to snap the form to a screen edge? This is not about letting the user do anything but the program positioning its window. (To allow the user to do that, the ScreenSnap property is no longer necessary in Windows 10.) Share this post Link to post
dummzeuch 1505 Posted August 28, 2022 1 hour ago, Vandrovnik said: Setting form's Left works fine for me. I have autogenerated manifest, enabled runtime themes and "Per monitor v2" DPI Awarrness. Instead of setting Left to -7, I set it to minus (GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)), which is -8 on my PC. Hm, that seems to be kind of a magical value, because if I use that rather then the -7, it works. It's also -8 on my PC. Share this post Link to post
Uwe Raabe 2057 Posted August 28, 2022 WindowState := TWindowState.wsMaximized; var L := Left; WindowState := TWindowState.wsNormal; Left := L; Share this post Link to post
Uwe Raabe 2057 Posted August 28, 2022 Alternative: Left := - (Width - ClientWidth) div 2; Share this post Link to post
dummzeuch 1505 Posted August 28, 2022 btw: https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543 (I knew I read about this somewhere, just didn't remember were.) Share this post Link to post
dummzeuch 1505 Posted August 28, 2022 (edited) OK, so Left := -(GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)); works for Left (actually it's Left := Form.Monitor.WorkAreaRect.Left - (GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)); because the left edge of the monitor might not be at pixel 0). It does not work for the height though: Height := Form.Monitor.WorkAreaRect.Height + 2* (GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER)); still leaves a gap to the bottom border of the monitor. But that's consistent with Windows + Left (but not with maximizing the window) Edited August 28, 2022 by dummzeuch Share this post Link to post
Vandrovnik 214 Posted August 28, 2022 For the "y" direction, there is SM_CYSIZEFRAME. Share this post Link to post
dummzeuch 1505 Posted August 28, 2022 12 minutes ago, Vandrovnik said: For the "y" direction, there is SM_CYSIZEFRAME. That doesn't work either. If I subtract if from the top, the title bar gets partly clipped and if I add it to the height, it has no effect. Share this post Link to post