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

How can I add .Resize() and .Moved() methods to _SCREEN?

Forms & Screen

How can I add .Resize() and .Moved() methods to _SCREEN?

by  ChrisRChamberlain  Posted    (Edited  )
If you want to manipulate child forms in relation to [color blue]_SCREEN[color black] and [color blue]_SCREEN[color black] in relation to child forms, and start your application in the last position on screen, you need to add both [color blue].Resize()[color black] and [color blue].Moved()[color black] methods to [color blue]_SCREEN[color black].

In the root of main.prg put
[color blue]
DO ScreenResizeClass
[color black]
Then create a procedure :-
[color green]
* *********************************
* Procedure: ScreenResizeClass
* Syntax: DO ScreenResizeClass
* *********************************[color blue]
PROC ScreenResizeClass
[color green]
* IF you are using VFP 8.0 SP1, replace the first 6 lines of the procedure with the following code

* PUBLIC oScreenHandler
* oScreenHandler = NEWOBJECT([ScreenHandler])

* BINDEVENT(_SCREEN,[Resize],oScreenHandler,[ResizeScreen])

* DEFINE CLASS ScreenHandler AS Session
* PROCEDURE ResizeScreen
* WITH _SCREEN
* .LockScreen = .T.
* && Code
[color blue]
DEFINE CLASS Resizer AS Custom
oScreen = _SCREEN

PROCEDURE oScreen.Resize
WITH _SCREEN
.LockScreen = .T.
[color green]&& Code[color blue]
.LockScreen = .F.
ENDW

IF VARTYPE(oMain) = [O]
WITH oMain
.LockScreen = .T.
[color green]&& Code[color blue]
.LockScreen = .F.
ENDW
ENDI

IF VARTYPE(oChild1) = [O]
WITH oChild1
.LockScreen = .T.
[color green]&& Code[color blue]
.LockScreen = .F.
ENDW
ENDI

IF VARTYPE(oChild2) = [O]
WITH oChild2
.LockScreen = .T.
[color green]&& Code[color blue]
.LockScreen = .F.
ENDW
ENDI

IF VARTYPE(oStatusBar) = [O]
WITH oStatusBar
.LockScreen = .T.
[color green]&& Code[color blue]
.LockScreen = .F.
ENDW
ENDI
ENDPROC
ENDDEFINE
[color black]
If you are not using VFP 8.0 SP1, in the [color blue].Load()[color black] event of your main form put :-
[color blue]
WITH _SCREEN
.AddObject([oResizer],[Resizer])
.AddObject([oScreenMoved],[ScreenMoved])
ENDW
[color black]
As you can see, you can add a [color blue].Moved()[color black] method which enables you to write the coordinates of [color blue]_SCREEN[color black] to a table so that the app always starts in the last position.

The code for the procedure, [color blue]ScreenMovedClass[color black], ([color blue]_SCREEN.Moved()[color black]), should follow the style of the [color blue]ScreenResizeClass[color black] procedure, excepting that you only need a code segment for [color blue]_SCREEN[color black].

In the example code above, you will find a reference to [color blue]oStatusBar[color black] - see 'How can I create my own statusbar?' - faq184-3155 for details.

What other code do you put in these methods?

[color blue]_SCREEN.Resize()[color black] should only be called from a resizable child forms' [color blue].Resize()[color black] event so that [color blue]_SCREEN[color black] can be resized in relation to the dimensions of the child form.

You will find it easier to perform the resizing/positioning of controls in all the child forms of an application in the [color blue]_SCREEN.Resize()[color black] method.

Equally, [color blue]_SCREEN.Resize()[color black] should contain code to resize all child forms when you resize [color blue]_SCREEN[color black].

To prevent recursive calls to resizable child forms, add a new property, [color blue].lInProcess[color black], to each resizable child form.

In the [color blue].Resize()[color black] event of the resizable child form, put :-
[color blue]
IF THIS.lInProcess = .F.
[tab]_SCREEN.Resize()
ENDI
[color black]
In the first line of [color blue]_SCREEN.Resize()[color black], put :-
[color blue]
oChild1.lInProcess = .T.
[color black]
In the last line of [color blue]_SCREEN.Resize()[color black], put :-
[color blue]
oChild1.lInProcess = .F.
[color black]
After the code segments for the individual objects in [color blue]_SCREEN.Resize()[color black], you can write the relevant coordinates of child forms and their controls and [color blue]_SCREEN[color black] to a table.

When you initialise the application next time, use the coordinates from the table to position and size[color blue] _SCREEN[color black], position and size child forms, and position and size controls in child forms.

Additional discussion of this FAQ can be found at thread184-742923

Have fun! [smile]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top