Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Move

This method lets you move an object. You can resize it at the same time.

Usage

oObject.Move( nLeft [, nTop [, nWidth [, nHeight ] ] ] )

The parameters are the new values for the specified properties. We can think of some fun things to do with movable controls. (Imagine a button that jumps away when the user clicks on it. Or don’t just imagine it—see the example.)

Example

* This might be the Click for a command button.
This.Move(This.Left + This.Width/4, ;
          This.Top - 50, This.Width / 2, This.Height * 3 / 2)
=inkey(.1)  && stop and let the user see
This.Move(This.Left - This.Width / 2, ;
          This.Top + 50, This.Width * 2, This.Height * 2 / 3)

The example points out that moving an object relative to its position, or sizing it relative to its size, is something of a pain. For an object that needed to do this a lot, we’d be inclined to create a custom method RelativeMove that would understand its parameters as relative to current position and size. Here’s the code:

* RelativeMove - a custom method
* Pass positive values to move right and down and to make object larger
* Pass negative values to move left and up and to make object smaller
LPARAMETERS nLeft, nTop, nWidth, nHeight
LOCAL nNewLeft, nNewTop, nNewWidth, nNewHeight
 
nNewLeft   = IIF( VARTYPE('nLeft')="N", This.Left + nLeft, This.Left)
nNewTop    = IIF( VARTYPE('nTop')="N", This.Top + nTop, This.Top)
nNewWidth  = IIF( VARTYPE('nWidth')="N", This.Width + nWidth, This.Width)
nNewHeight = IIF( VARTYPE('nHeight')="N", This.Height + nHeight, This.Height)
 
This.Move(nNewLeft, nNewTop, nNewWidth, nNewHeight)
 
ENDPROC

See Also

Moved, Resize