Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to check the current screen resolution?
Message
From
29/11/2021 13:50:25
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01682835
Message ID:
01682859
Views:
88
This message has been marked as the solution to the initial question of the thread.
Likes (1)
For one of my clients, the base form class includes a method that checks the form size against the VFP viewport and, if necessary, resizes the form to fit inside the viewport. (It works together with my code for changing font size when the form size changes.) Here's the code that resizes the form:
* Check whether this form fits inside the available space.
* If not, shrink it.

LOCAL lnAvailHeight, lnAvailWidth
LOCAL lnDesiredHeight, lnDesiredWidth, llResize
LOCAL lnResizeRatio, lnTop

lnAvailHeight = _screen.ViewPortHeight
lnAvailWidth = _screen.ViewPortWidth
llResize = .F.

* Include a little fudge factor
IF This.Height > lnAvailHeight - 50
	lnDesiredHeight = m.lnAvailHeight - 50
	llResize = .T.
ELSE
	lnDesiredHeight = This.Height
ENDIF

*-- TEG 6/7/2021 
* Don't need fudge factor for width. We don't put anything on the sides.
IF This.Width > m.lnAvailWidth && - 50
	lnDesiredWidth = m.lnAvailWidth - 50 
	llResize = .T.
ELSE
	lnDesiredWidth = This.Width
ENDIF


IF m.llResize
	lnTop = This.Top
	
	* Figure out which dimension is more cramped
	IF m.lnDesiredHeight/This.Height < m.lnDesiredWidth/This.Width
		lnResizeRatio = m.lnDesiredHeight/This.Height
	ELSE
		lnResizeRatio = m.lnDesiredWidth/This.Width
	ENDIF
	
	This.Height = FLOOR(m.lnResizeRatio * This.Height)
	This.Width = FLOOR(m.lnResizeRatio * This.Width)

	* Now make sure top is visible
	IF This.AutoCenter
		This.AutoCenter = .F.
		This.AutoCenter = .T.
	ELSE
		This.Top = m.lnTop
	ENDIF
	
ENDIF

RETURN 
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform