Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proportional resizing of forms
Message
 
To
20/02/2023 13:11:01
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01686228
Message ID:
01686229
Views:
81
Hi Tamar,

Maybe this ...
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (x:\xfrx\test\customers\tamar.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   02/20/23 07:57:01 PM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 275
	Width = 406
	DoCreate = .T.
	Caption = "Form1"
	oldwidth = 0
	oldheight = 0
	Name = "Form1"


	ADD OBJECT edit1 AS editbox WITH ;
		Height = 120, ;
		Left = 12, ;
		Top = 11, ;
		Width = 189, ;
		Name = "Edit1"


	ADD OBJECT edit2 AS editbox WITH ;
		Height = 120, ;
		Left = 205, ;
		Top = 143, ;
		Width = 189, ;
		Name = "Edit2"


	PROCEDURE Resize
		*LOCAL 

		lnRatioY = This.Height/This.OldHeight
		lnRatioX = This.Width/This.OldWidth


		WITH This.edit1
		.Move(.nOrigLeft*lnRatioX, .nOrigTop*lnRatioY, .nOrigWidth*lnRatioX, .nOrigHeight*lnRatioY)
		ENDWITH

		WITH This.edit2
		.Move(.nOrigLeft*lnRatioX, .nOrigTop*lnRatioY, .nOrigWidth*lnRatioX, .nOrigHeight*lnRatioY)
		ENDWITH
	ENDPROC


	PROCEDURE Init
		This.OldWidth=This.Width
		This.OldHeight=This.Height
	ENDPROC


	PROCEDURE edit1.Init
		This.AddProperty("nOrigWidth", This.Width) 
		This.AddProperty("nOrigHeight", This.Height) 
		This.AddProperty("nOrigLeft", This.Left) 
		This.AddProperty("nOrigTop", This.Top) 
	ENDPROC


	PROCEDURE edit2.Init
		This.AddProperty("nOrigWidth", This.Width) 
		This.AddProperty("nOrigHeight", This.Height) 
		This.AddProperty("nOrigLeft", This.Left) 
		This.AddProperty("nOrigTop", This.Top) 
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
*************************************************
MartinaJ


>Has anyone been successful in forcing VFP forms to resize only proportionally?
>
>I'm working on an application where we allow users to resize forms and we change font sizes to match the new form size. The idea is that we can design for a screen size that we're sure all users have, but we can also allow users with larger/higher precision monitors or vision issues to resize in order to ensure they can read the forms. It works pretty well, except that sometimes users screw up the aspect ratio of a form in a way that makes it look lousy. Since there's no reason to allow users to change the aspect ratio, we want to prevent it.
>
>I've been experimenting with a simple base class form to figure out how to do this (and to ensure that other code in our framework doesn't mess things up, while I figure out how to do this) and I'm finding it harder than I expected. I added properties to the form to hold the original height and width (which we're already doing in our existing resizing code) and the most recent height and width and put code in Init to set both pairs to the original height and width.
>
>Then, in Resize, I have code to see what has changed and adjust either Height or Width to match the change in the other. The code works pretty well when the user drags diagonally, but it's awful when the user drags either horizontally or vertically. After a lot of experimentation, what I'm seeing is that when I change either Height or Width in Resize, the change doesn't (always?) take and on the next call to Resize, that dimension is the same as before (or nearly the same as the user is still dragging). I sort of get it because you're still inside a MouseDown/MouseUp cycle (except MouseUp and MouseDown don't actually fire for resizing). As far as I can tell, the only event that fires around resizing is Resize itself. There's nothing that fires when the resize is finished.
>
>Here's my code in Resize, including a long comment that explains the strategy I'm using:
>
>
>LOCAL lnNewHeight, lnNewWidth
>
>lnNewHeight = This.Height
>lnNewWidth = This.Width
>
>LOCAL lnOldRatio, lnNewRatio
>
>lnOldRatio = This.nOrigHeight/This.nOrigWidth
>lnNewRatio = m.lnNewHeight/m.lnNewWidth
>
>* Lay out cases
>*   Case 1: Same --> we're done
>*   Case 2: lnNewRatio > lnOldRatio
>*     Case 2a: lnNewHeight > This.nLastHeight --> height grew more than width, fix width
>*     Case 2b: lnNewHeight < This.nLastHeight --> width shrunk more than height, fix height
>*     Case 2c: heights are the same --> width shrunk more than height, fix height
>*   Case 3: lnNewRatio < lnOldRatio
>*     Case 3a: lnNewHeight < This.nLastHeight --> height shrunk more than width, fix width
>*     Case 3b: lnNewHeight > This.nLastHeight --> width grew more than height, fix height
>*     Case 3c: heights are the same --> width grew more than height, fix height
>*
>* Fix height --> This.nOrigHeight * (m.lnNewWidth/This.nOrigWidth)
>* Fix width  --> This.nOrigWidth * (m.lnNewHeight/This.nOrigHeight)
>*
>* Examples:
>*   Assume This.nOrigHeight = 4 and This.nOrigWidth = 2, so lnOldRatio = 2
>*   Each example assumes starting from original, not previous case
>*   
>*   lnNewHeight  |  lnNewWidth   |  lnNewRatio   |  Case  | Result
>*        5       |       2       |      2.5      |   2a   |  set width to 2.5
>*        5       |       3       |      1.67     |   3b   |  set height to 6
>*        4       |       3       |      1.33     |   3c   |  set height to 6
>*        3       |       2       |      1.5      |   3a   |  set width to 1.5
>*        3       |       1       |      3        |   2b   |  set height to 2
>*        4       |       1       |      4        |   2c   |  set height to 2
>
>
>DO CASE 
>CASE m.lnNewRatio = m.lnOldRatio && Case 1
>   * Nothing to do, just get out
>   
>CASE m.lnNewRatio > m.lnOldRatio && Case 2
>   IF m.lnNewHeight > This.nLastHeight
>      * Case 2a
>      This.Width = ROUND(This.nOrigWidth * m.lnNewHeight / This.nOrigHeight, 0)
>   ELSE 
>      * Case 2b and 2c
>      This.Height = ROUND(This.nOrigHeight * m.lnNewWidth / This.nOrigWidth, 0)
>   ENDIF 
>   
>CASE m.lnNewRatio < m.lnOldRatio && Case 3
>   IF m.lnNewHeight < This.nLastHeight
>      * Case 3a
>      This.Width = ROUND(This.nOrigWidth * m.lnNewHeight / This.nOrigHeight, 0)
>   ELSE 
>      * Case 3b and 3c
>      This.Height = ROUND(This.nOrigHeight * m.lnNewWidth / This.nOrigWidth, 0)
>   ENDIF       
>
>ENDCASE
>
>This.nLastHeight = This.Height
>This.nLastWidth = This.Width
>
>RETURN
>
>
>If anyone sees somewhere that I'm off-track, please tell me. Also, if anyone has done this successfully, please tell me how.
>
>Tamar
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform