dragging of a button

dragging of a button

Postby Otto » Fri Feb 13, 2015 4:42 pm

Hello, I would like to limit dragging of a button only to vertically.
Can someone please help me.
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: dragging of a button

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


Code: Select all  Expand view  RUN
        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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: dragging of a button

Postby Otto » Sat Feb 14, 2015 1: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: dragging of a button

Postby ukoenig » Sat Feb 14, 2015 4:36 pm

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  RUN

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 :)
Last edited by ukoenig on Sun Feb 15, 2015 1:12 pm, edited 1 time in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: dragging of a button

Postby Otto » Sat Feb 14, 2015 10:45 pm

Hallo Uwe,
herzlichen Dank.
Kannst du bitte das gesamte Beispiel posten.
Liebe Grüße
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: dragging of a button

Postby ukoenig » Sun Feb 15, 2015 1: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

Image

best regards
Uwe :)
Last edited by ukoenig on Sun Feb 15, 2015 8:23 pm, edited 1 time in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: dragging of a button

Postby Otto » Sun Feb 15, 2015 6:45 pm

Hallo Uwe,
herzlichen Dank.
Ich probiere nun deine Funktion in mein Programm einzubauen.
lg
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: dragging of a button

Postby ukoenig » Sun Feb 15, 2015 8: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

Image

Image

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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests