Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows appearing off edge of screen (Delphi)

Windows in my application are popping up off the edge of the screen, and this of course is a problem because some of the windows are modal and can't be dismissed (you don't even know they are there).

I'm using the TurboPower Orpheus component which remembers the location and size of each form, then restores it when the form is shown again. It saves the size and placement in an INI file.

What can I do to prevent windows from ever showing off the side of the screen?

like image 458
Daisetsu Avatar asked Dec 17 '22 23:12

Daisetsu


2 Answers

It's common for this sort of thing to happen if you use multiple monitors and then disconnect one, such as when undocking a laptop. Or if you dock a laptop to a screen with a higher resolution. Or use remote desktop, etc.. The remedy is to override the "remember my position" behavior with a sanity check, to see if the left+width exceeds the width of the screen (Screen.Monitors array, actually - thanks guys), and vice-versa for the top+height.

Ideally, you "bump" by subtracting the difference, so you're butting up against the edge that the window wanted to straddle.

Also, see if there are updates to Orpheus that fix this. If not, you can get the source, make the correction (optional), and contribute it back to the project. It's OSS, as I recall.

like image 114
Chris Thornton Avatar answered Dec 27 '22 21:12

Chris Thornton


You may want to give a look at their DefaultMonitor property and read the code from TCustomForm.SetWindowToMonitor to see how to deal with positioning relatively to Screen.Monitors.

Use DefaultMonitor to associate a form with a particular monitor in a multi-monitor application. The following table lists the possible values: 

Value        Meaning  
dmDesktop    No attempt is made to position the form on a specific monitor.   
dmPrimary    The form is positioned on the first monitor listed in the global screen object's Monitors property.   
dmMainForm   The form appears on the same monitor as the application's main form.   
dmActiveForm The form appears on the same monitor as the currently active form.   

Note: DefaultMonitor has no effect if the application does not have a main form.
like image 40
Francesca Avatar answered Dec 27 '22 19:12

Francesca