Make your own free website on Tripod.com

Nice for on a about box, a close button which runs away if you want to press on it.

Back Up Next

Author: Eric Aling
Accessed:

Place a commandbutton on a window. For the commandbutton, create an INTEGER instance variable ii_i and map the pbm_mousemove event to an userevent ue_mousemove.

Code in the ue_mousemove event:



long ll_x, ll_nx, ll_xo
long ll_y, ll_ny, ll_yo
long ll_i long ll_xc,ll_yc

/* display some annoyig text */

ii_i++

CHOOSE CASE ii_i
CASE 100
	This.Text = "Haha"
CASE 125
	This.Text = "Catch"
CASE 150
	This.Text = "me"
CASE 175
	This.Text = "if"
CASE 200
	This.Text = "you"
CASE 225
	This.Text = "can!!"
CASE 300
	This.Text = "Close"
CASE 400
	This.Text = "Press"
CASE 410
	This.Text = "Esc!"
CASE 450
	This.Text = "Close"
	ii_i = 0
END CHOOSE

/* get current position of pointer */

ll_x = This.PointerX()
ll_y = This.PointerY()

/* move commandbutton based n this position */

IF ll_x < (This.Width / 2) THEN
	ll_nx = This.X + 10
ELSE
	ll_nx = This.X - 10 
END IF

IF ll_y < (This.Height / 2) THEN
	ll_ny = This.Y + 10
ELSE
	ll_ny = This.Y - 10
END IF 

/* if borders are reached, move back to center, else move to new position */

IF 	ll_nx < 1 OR &
	ll_nx > ( Parent.Width - This.Width - 10) OR &
	ll_ny < 1 OR &
	ll_ny > ( Parent.Height - (This.Height + 100)) THEN

	ll_xc = (Parent.Width - This.Width) / 2
	ll_yc = (Parent.Height - This.Height) / 2
	ll_xo = This.x
	ll_yo = This.y

	FOR ll_i = 1 TO 100

		This.move( ll_xo + (( ll_xc - ll_xo )/100)*ll_i, &
		ll_yo + (( ll_yc - ll_yo )/100)*ll_i )

	NEXT 

ELSE 

	This.move(ll_nx,ll_ny) 

END IF

In the clicked event code Close(parent) and make the commandbutton the 'cancel' button ( by selecting the cancel propery ).

Back Up Next