Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dragdrop to reposition a label or textbox

Status
Not open for further replies.

samsnead

Programmer
Sep 3, 2005
100
CA
I want to give users ability to move fields on a form (at runtime) then save those field positions. I have built a table that will hold the positions but have not found how to drag a label from one position on the form to another. Can I do this? Same for textbox?

Application - we have designed a form that is a duplicate of an FRX. We want user to be able to position items on the form then we have code that will update the frx. Why - because users find the report tools complex and hard to use and we have more control over what they can do on the form.
 
I have reviewed "How can a user modify a report without using the FoxPro report designer "
faq184-157

but still having problems
 
I did something similar with images/thumbnails, but the basics should be the same.

What I did was create basically, a blank form. The DragMode of which is set to 'Automatic'
I then added the objects at runtime, which got their properties from a table, such as x-y coordinates, type, name, etc.
These also had DragMode set to 'Automatic'.

Now each time an object gets moved, the DragDrop event fires, so you can add code similar to the following to update their position in the table:
Code:
LPARAMETERS oSource, nXCoord, nYCoord
*... nXCoord = column
*... nYCoord = row

IF nXCoord < 1  &&... off the edge
   nXCoord = 0
ENDIF

IF nYCoord < 1  &&... off the top
   nYCoord = 0
ENDIF

*... update position of game
IF SEEK(oSource.NAME, 'vlayout', 'objname')
   REPLACE vlayout.l_rown WITH nYCoord
   REPLACE vlayout.l_coln WITH nXCoord
   oSource.MOVE(nXCoord, nYCoord)
   opLastClicked = oSource
ENDIF

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thanks Dave - that helps a bit - no success yet - now I can get the label to move (but not to where I want) - I put following code in the oledragdrop method, set oledragmode to automatic and oledropmode to 1(enabled). Label is also in a container (wouldn't move at all if just on form)

LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord

this.Move(nXCoord,nYCoord)
thisform.calctop(this.Name,this.Top,this.left)
 
I can't seem to get a label to work with OLE drag and drop on a form. Try using VFP's native drag and drop by setting DragMode on and putting the code in the form's DragDrop method.

Tamar
 
This works - but again it doesn't move label to correct position - If I click on label and drag - doesn't move. If I click again on label, it moves - usually down and right - never to the left! I did find three page write up in the VFP9 help so am going to review that. Thanks for the help
 
What sort of a container do you have the the label on?
I just put a label on a blank form. The Label's 'DragMode' property is set to Automatic, and this code in the form's DragDrop event:
Code:
LPARAMETERS oSource, nXCoord, nYCoord
oSource.Move(nXCoord, nYCoord)

RETURN

If you are using a pageframe, you'll have to put the code in the page of the pageframe where the label is.
In other words, the parent container.

To get perfect positioning though, you have to compensate for the size of the label. Like, take the length and divide it by 2.

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave - I found a sample form in the vfp9 samples\solution\forms directory (ddrop.scx) - code is clear and should be easy to implement now - they have sample where you move a button around and does exactly what I want.

In the page dragdrop code the have following:

LPARAMETERS oSource, nXCoord, nYCoord
oSource.Left = nXCoord - THISFORM.XOffset
oSource.Top = nYCoord - THISFORM.YOffset

In the button dragdrop code they have
LPARAMETERS oSource, nXCoord, nYCoord
THIS.Parent.DragDrop(oSource, nXCoord, nYCoord)

both are set to manual - I will let you know how it goes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top