When the form is displayed, I will do all the checks (if the monitor number -i- exists, etc.), if everything is ok, I will be on the right monitor Show the form on (i)
Form1.BoundsRect := Screen.Monitors[i].BoundsRect;
I want to be able to enter the Form1.onCloseQuery event The form displayed by the current monitor and the activity monitor are displayed in the current monitor, so that I can save the information in some Ini, DB, anyway, but it seems that I can’t find the correct way to execute it normally.
Any ideas?
In other words, you don’t actually need to worry about where the form is Monitor. For example, suppose you have two 800×600 monitors side by side. The screen coordinates are:
>(0,0,800,800)Left hand monitor.
>(800,0,1600,800 ) Is used on the right monitor.
When you display the form for the first time, it is wise to check if the form is within the range of the screen. Maybe when you remember its location, it is on the display, It was later removed. Or the user may have reconfigured their monitor to invalidate the previous screen coordinates.
To answer your question, please use the Monitor
property of the form Find the monitor associated with the form. This is achieved by calling the Win32 API function MonitorFromWindow
and passing MONITOR_DEFAULTTONEAREST.
In a multi-monitor environment , I want to be able to get the current monitor and activity monitor to save the information when I close the form, and when I reopen the form later, the form will be displayed in the last position it is displayed.
When When the form is displayed, I will perform all checks (if the monitor number -i-exists, etc.), if everything is normal, I will display the form on the right monitor (i)
Form1.BoundsRect := Screen.Monitors[i].BoundsRect;
I want to be able to display the form displayed by the current monitor and the active monitor in the Form1.onCloseQuery event, so that I can Save this information in some Ini, DB, anyway, but it seems that I can’t find the correct way to execute it normally.
Any ideas?
If you want to save the position of the form, you can do this in screen coordinates. Save the information in TForm.BoundsRect, which provides you with screen relative coordinates. Note that the screen relative coordinates include all monitors connected to the screen.
In other words, you don’t actually need to worry about the monitor the form is on. For example, suppose you have two side by side 800×600 display. The screen coordinates are:
>(0,0,800,800) left-hand monitor.
>(800,0,1600,800) is used for right monitor.
When you display the form for the first time, it is wise to check if the form is within the range of the screen. Maybe when you remember its location, it was on the display and was later removed. Or the user may have reconfigured Its monitor to invalidate the previous screen coordinates.
To answer your question, please use the Monitor
attribute of the form to find the monitor associated with the form. This is done by calling The Win32 API function MonitorFromWindow
is implemented by passing MONITOR_DEFAULTTONEAREST.