Page 1 of 1

dragging of a button

PostPosted: Fri Feb 13, 2015 4:42 pm
by Otto
Hello, I would like to limit dragging of a button only to vertically.
Can someone please help me.
Thanks in advance
Otto

Re: dragging of a button

PostPosted: Sat Feb 14, 2015 8:40 am
by Antonio Linares
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: Select all  Expand view
           if Valtype( ::bDrag ) == 'B'
               Eval( ::bDrag, ::nTop + nRow - nMRow, ::nLeft + nCol - nMCol )
            endif


Code: Select all  Expand view
        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.

Re: dragging of a button

PostPosted: Sat Feb 14, 2015 1:40 pm
by Otto
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

Re: dragging of a button

PostPosted: Sat Feb 14, 2015 4:36 pm
by ukoenig
Otto,

I created a little test

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

Image

Image

Image

Image

The calculation :

Code: Select all  Expand view

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

Re: dragging of a button

PostPosted: Sat Feb 14, 2015 10:45 pm
by Otto
Hallo Uwe,
herzlichen Dank.
Kannst du bitte das gesamte Beispiel posten.
Liebe Grüße
Otto

Re: dragging of a button

PostPosted: Sun Feb 15, 2015 1:04 pm
by ukoenig
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

Image

best regards
Uwe :)

Re: dragging of a button

PostPosted: Sun Feb 15, 2015 6:45 pm
by Otto
Hallo Uwe,
herzlichen Dank.
Ich probiere nun deine Funktion in mein Programm einzubauen.
lg
Otto

Re: dragging of a button

PostPosted: Sun Feb 15, 2015 8:25 pm
by ukoenig
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

Image

Image

best regards
Uwe :)