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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ALLOW MY FORM TO FIT ON ANY MONITOR RESOLUTION

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi Guys,
I would like to know what can i do to make my form, from my application to fit on any monitor, depending of the monitor resolution ?

in other words, the application will run from different computers and all of them have different resolution, just need to know what do i need to declare, to make the form to adopt it is size, according to the resolution from the computer is running.
Thanks a lot in advance
 
There are three concepts for this:

1. Don't care, write for a small size fitting any screen and center it (surely not what you want).
2. Use a resizer class (mwresize from Markus Winhard), which adapts most of a form including font sizes.
3. Use anchoring.

The downside of 2 is, it doesn't work as automatic with some more complex controls with inner structures like columns, eg grids or listboxes, also you don't make use of the extra space, everything just gets bigger.
Anchoring (3) also doesn't automatically resize grid columns, but you can anchor in some fashionable ways. Eg a listbox or grid get's height rises without the font size, so you can see more items.

I'd prefer anchoring, see [URL unfurl="true"]http://www.tomorrowssolutionsllc.com/Articles/Anchoring%20controls%20on%20forms.PDF[/url] for more details on it.

Bye, Olaf.
 
I have used the Windows GETSYSTEMMETRICS function to handle when going between work (local) and home (remote). Why? For example, I added a second monitor at work and placed some apps on the secondary monitor. Then when I went home to a single smaller monitor (1080 lines reduced from 1200) and remotely logged in, I discovered my apps that saved TOP, LEFT, HEIGHT and WIDTH pixels were off screen. The commercial apps automatically shifted onto the primary monitor, though I think NotePad just edged onto the screen so I had to pull it onscreen the rest of the way.

Check the MS web pages for a complete list of parameters and usage details but this is what I have used in my apps:

Code:
* Adjust window screen size and location if screen dimensions are smaller
myAppWindowConfigFile = "insert file location here.txt"
lcConfigData = FILETOSTR(myAppWindowConfigFile)
* Window screen size and location
DO CASE
CASE EMPTY(lcConfigData)
	* no config file data saved from prior session
CASE "|MAXIMIZED|"$lcConfigData
	myVfpObj.WindowState = 2  && set Maximized -- 0=Normal 1=Minimized 2=Maximized
OTHERWISE
	myVfpObj.WindowState = 0  && set Normal
	myVfpObj.Top =  IIF("|TOP|"$lcConfigData,  VAL(STREXTRACT(lcConfigData,"|TOP|","|")),  myVfpObj.Top)
	myVfpObj.Left = IIF("|LEFT|"$lcConfigData, VAL(STREXTRACT(lcConfigData,"|LEFT|","|")), myVfpObj.Left)
	myVfpObj.Height = IIF("|HEIGHT|"$lcConfigData, VAL(STREXTRACT(lcConfigData,"|HEIGHT|","|")), myVfpObj.Height)
	myVfpObj.Width  = IIF("|WIDTH|"$lcConfigData,  VAL(STREXTRACT(lcConfigData,"|WIDTH|","|")),  myVfpObj.Width)
	* Retrieve existing Windows desktop size in case prior saved state is now offscreen
	DECLARE INTEGER GetSystemMetrics IN user32 INTEGER nIndex
	myVfpObj.Top =  IIF( BETWEEN(myVfpObj.Top, GetSystemMetrics(77), GetSystemMetrics(77)+GetSystemMetrics(79)), myVfpObj.Top, 20 )
	myVfpObj.Left =  IIF( BETWEEN(myVfpObj.Left, GetSystemMetrics(76), GetSystemMetrics(76)+GetSystemMetrics(78)), myVfpObj.Left, 20 )
	myVfpObj.Height =  IIF( BETWEEN(myVfpObj.Height, 20, GetSystemMetrics(17)), myVfpObj.Height, GetSystemMetrics(17)-40 )
	myVfpObj.Width =  IIF( BETWEEN(myVfpObj.Width, 20, GetSystemMetrics(16)), myVfpObj.Width, GetSystemMetrics(16)-80 )
ENDCASE
 
These are the GetSystemMetrics parameter values you are most likely to reference:
* Screen Height
#DEFINE SM_CXSCREEN 0
* Screen Width
#DEFINE SM_CYSCREEN 1
* Desktop Screen Height
#DEFINE SM_CXFULLSCREEN 16
* Desktop Screen Width
#DEFINE SM_CYFULLSCREEN 17
* Virtual Left
#DEFINE SM_XVIRTUALSCREEN 76
* Virtual Top
#DEFINE SM_YVIRTUALSCREEN 77
* Virtual Width
#DEFINE SM_CXVIRTUALSCREEN 78
* Virtual Height
#DEFINE SM_CYVIRTUALSCREEN 79
* Monitor Count
#DEFINE SM_CMONITORS 80


This sample code should set the window to Normal, Sizable and 20 pixels in from screen edges:
Code:
DECLARE INTEGER GetSystemMetrics IN user32 INTEGER nIndex
* General settings
myVfpObj.WindowState = 0 && 0=Normal 1=Minimized 2=Maximized
myVfpObj.BorderStyle = 3 && 0=No Border 1=Fixed Single 2=Fixed Dialog 3=Resizable (changes Height +90 if was set to 1)
* Session settings
myVfpObj.Top =    20
myVfpObj.Left =   20
myVfpObj.Height = GetSystemMetrics(17)-40
myVfpObj.Width =  GetSystemMetrics(16)-40
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top