Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen Positioning for User Forms

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
Anyone know how I can use API functions (I'm assuming it would be API functions) to detect how many monitors a user is using and then decide which monotor to display user forms on?

-Joshua
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 

What you can use is [tt]Screen.Height [/tt] and [tt]Screen.Width[/tt] and find the ratio between the two, and based on that information detect if you have 1 or 2 monitors.

You need to take under consideration the task bar if you need to be exact.

Have fun.

---- Andy
 
Rather than detecting the number of monitors and having the app decide where to place the forms it may be prefereable to let the user place Forms on the monitor he chooses during app use; when he does that or when the app closes you record the Top/ Left position of each Form (in an associated text file or Excel Sheet perhaps); when he restarts the app or a Form is opened the Last Top/ Left position of it can be restored. You can then determine if those coordinates represent a legal (visible) one for the current monitor setup using the MonitorFromRect API, if it not legal move it to the primary or nearest monitor. The API works for vb6 Forms I have not tested it for UserForms.
This approach saves you the chore of maintaining a monitor 'map' and the associated logic.
 
This is really problematic! The rules for default positioning leave much to be desired. If the various Top/Left/Width/Height properties aren't good enough for you, the EnumDisplayMonitors API is as good a place as any to start.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top