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
>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 >>