FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour dragging of a button
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

dragging of a button

Posted: Fri Feb 13, 2015 04:42 PM

Hello, I would like to limit dragging of a button only to vertically.
Can someone please help me.
Thanks in advance
Otto

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: dragging of a button

Posted: Sat Feb 14, 2015 08:40 AM
Otto,

The right way would be to redefine Methods MouseMove() and LButtonUp() of Class TControl,
but in order to make it simpler you may try to use the DATAs bDrag and bPostDrag (both are codeblocks).

See the parameters that they use. bDrag is evaluated when the control is moving, bPostDrag only once when
the mouse button is released:

Code (fw): Select all Collapse
            if Valtype( ::bDrag ) == 'B'
               Eval( ::bDrag, ::nTop + nRow - nMRow, ::nLeft + nCol - nMCol )
            endif


Code (fw): Select all Collapse
         if lMoved .AND. valtype( ::bPostDrag ) == 'B'
             Eval( ::bPostDrag, SELF )
         endif


using those codeblocks you may control the new coordinates of the button, and modify them to allow the vertical move only.

I have not tested it myself, but it may work and it is much easier than redefining both methods.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: dragging of a button

Posted: Sat Feb 14, 2015 01:40 PM

Dear Antonio,
thank you for your help.
oBtn:bDrag := { | y,x,flags | oBtn:nLeft := 1000 }
For testing purpose I tried the following codeblock and it seems I can achieve what I want to do.
Best regards,
Otto

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: dragging of a button

Posted: Sat Feb 14, 2015 04:36 PM
Otto,

I created a little test

I used a Group in design-mode to define a area
It works in all directions.









The calculation :

Code (fw): Select all Collapse
FUNCTION BTN_MOVE(oBtn3, x, y)
LOCAL nNewTop := x, nNewLeft := y, lNew := .F.

IF x < oGroup:nTop 
   nNewTop := oGroup:nTop
   lNew := .T.
ENDIF
IF y < oGroup:nLeft 
   nNewLeft := oGroup:nLeft
   lNew := .T.
ENDIF
IF x + oBtn3:nHeight > oGroup:nBottom  
   nNewTop := oGroup:nBottom - oBtn3:nHeight
   lNew := .T.
ENDIF
IF y + oBtn3:nWidth > oGroup:nRight  
   nNewLeft := oGroup:nRight - oBtn3:nWidth
   lNew := .T.
ENDIF

IF lNew = .T. // only moved on wrong area
   oBtn3:Move( nNewTop, nNewLeft, , , .T. )
ENDIF

RETURN( NIL )


best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: dragging of a button

Posted: Sat Feb 14, 2015 10:45 PM

Hallo Uwe,
herzlichen Dank.
Kannst du bitte das gesamte Beispiel posten.
Liebe Grüße
Otto

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: dragging of a button

Posted: Sun Feb 15, 2015 01:04 PM
Otto,

the Download ( 3,6 MB )

The button can be moved only inside the group
a right mouseclick inside the dialog ( NOT group ) opens a alert with informations about button and group. Just move and resize the group around the button


It works in the other direction as well.
I mean, moving or resizing the group, the button will be adjusted to the new position / size.


http://www.pflegeplus.com/DOWNLOADS/Movebtn1.zip



best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: dragging of a button

Posted: Sun Feb 15, 2015 06:45 PM

Hallo Uwe,
herzlichen Dank.
Ich probiere nun deine Funktion in mein Programm einzubauen.
lg
Otto

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: dragging of a button

Posted: Sun Feb 15, 2015 08:25 PM
Otto,
a little change, to move multiple buttons with different sizes

In short, what You need :

// LOCAL nNewPos[5][3] = 5 buttons

// the first Button, the array = nNewPos[1]
oBtn[1]:bDrag := { | x,y,flags | nNewPos[1] := BTN_MOVE(oBtn[1], x, y, oBtn[1]:nWidth, oBtn[1]:nHeight) }
oBtn[1]:bMoved := { || IIF( nNewPos[1][1] = .T., oBtn[1]:Move( nNewPos[1][2], nNewPos[1][3], , , .T. ), NIL ) }


ON INIT MAKE_AREA(oDlg) // only needed to find the area !

Maybe as a help to find the needed area, add these lines ( group ).
From the alert You can get the values.

FUNCTION MAKE_AREA(oDlg)
// Group-startposition and size : Top, Left, Bottom, Right
oGroup := TGroup():New( 100, 100, 300, 300, "", oDlg, NIL, NIL, .T. , .T. , NIL, .T. )
oGroup:SETCOLOR( , 23324454)
RETURN( NIL )

Replace the group-values with the needed values

FUNCTION BTN_MOVE(oBtn, x, y, nWidth, nHeight)
LOCAL nNewTop := x, nNewLeft := y, lMove := .F.
IF x < oGroup:nTop
nNewTop := oGroup:nTop + 8 // Why needed + 8 ??
lMove := .T.
ENDIF
IF y < oGroup:nLeft
nNewLeft := oGroup:nLeft
lMove := .T.
ENDIF
IF x + nHeight > oGroup:nBottom
nNewTop := oGroup:nBottom - nHeight
lMove := .T.
ENDIF
IF y + nWidth > oGroup:nRight
nNewLeft := oGroup:nRight - nWidth
lMove := .T.
ENDIF
RETURN( {lMove, nNewTop, nNewLeft} )


the Download ( 3,6 MB )

http://www.pflegeplus.com/DOWNLOADS/Movebtn2.zip





best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion