Do you know snipaste? It's very easy to use to snip a region of display and show the copied region on the topmost, so it's useful to contrast or input data.However, this software cannot be used in company, so I decided to create one with primary function of snipaste , and I almost completed it...Looks like there is something wrong when selected a region of display. Its position will be changed and its size will be scaled. I cannot figure out what happened.It there anyone could give me a hand?
If I run your script as-is from a PowerShell console on Screen 2 (100% scaling) and click/drag the mouse around the bounds of the Task Manager window I see this popup generated by your script (red border added by me for emphasis):
By default, powershell.exe and pwsh.exe are "DPI Unaware", which means that any graphics operations performed by Windows Forms are drawn in-memory at 100% scale regardless of the screen settings, and Windows will stretch the application window to match the scaling factor configured for the screen in Display Settings.
That's why in the second example the screen capture of Task Manager is larger than the original application - it's captured at 100%, and Windows Forms draws it at 100% in the popup but then Windows stretches the form and the image to 150% to display it on screen.
Your dimensions in your code are effectively "virtual pixel" sizes not "physical pixel" sizes. This is basically to support scaling in legacy applications that have no idea about display scaling (hence DPI Unaware).
To fix that you'll need to make your script DPI Aware - more specifically, "Per Monitor" DPI Aware. Then, the dimensions in your code will represent "physical pixel" sizes because Windows will leave your application to perform graphical scaling. Whether you actually do the scaling or not is up to you, but your code can now work in physical pixels.