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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and drop an object in an order on a form 1

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
337
GB
Hello

I hope I am able to explain what I am trying to achieve.

I created a quiz using VFP9 which basically asks the user to enter the required number in order of correct sequence e.g. 1, 3, 2, 6 etc. This order is entered into a column in a grid down the right hand side after which the user clicks a command button which stores the answer, rearranges the sequence and shows the user the order they have selected. The answered questions are stored until the end of the quiz.

There are varying amounts of answers in the quiz (sometimes 4, 6, 9 etc) shown in the grid for each question.

I found this and also researched this site but can't find the answer I'm looking for (and it's not something I have been involved with before)

What I'm trying to achieve is:

Show a form with perhaps command buttons containing the answer (they are only short answers)
Allow the user to drag those answers over and maybe onto some sort of rectangular area in the correct order of sequence
This would eliminate the need to enter the correct sequence numbers whereby the user could just put the answers in the sequence first hand

I am fairly confident with VFP9 so any suggestions, pointers or where I can find a basic example of something like this would be appreciated.



Thank you

Steve
 
Maybe instead of drag and drop, you could use point and click.
I have something similar on a form placing games on a location screen. Click the left-hand (source) object - which is an image control, then as the mouse moves over the 'target' control, the X and Y coordinates are updated in the MouseMove event. When the target object is clicked, I add a record to a table saving the source object name and the X/Y coordinates.

Drag and drop can work just as well too though. The MouseMove still updates the X/Y. Something to keep in mind is you have to make sure DragMode is set before it works.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Why not look into the samples solution?
But actually I would rather simply click on buttons of one buttongroup and in their click event make them invisible and add a corresponding button to a secondary button group.

Or even simpler: Make a listbox with moverbars=.T. and let users rearrange items inside the list.

Bye, Olaf.
 
Thank you for the suggestions which I will look into over the weekend. My thoughts on this however is that it would be easier for the user to click drag and drop the relevant answer into the relevant order. This could be done in flash but I'm a huge supporter of VFP9 and the answers etc are in tables.

Thank you

Steve
 
I suggested something in that direction, too. Look at the samples in the solution project.
To elaborate a bit more in the direction: You find it in the Task Pane and solutions are searchable.
There are two examples about drag and drop and one is about controls.

Bye, Olaf.
 
Olaf, will have a look today and I appreciate the further I info.

Thank you

Steve
 
Steve,

In fact, drag-and-dropp is not that difficult to implement in VFP. There are two broad approaches:

- The old way.

- The recommended way (using OLE drag and drop).

Normally, I would always recommend the second of these. However, for a simple case like this, the old way might be easier.

In summary:

- Set the control's DragMode property to 1.

- Write code in the control's DragDrop event. The code should do whatever action you want to take place when the user drops the control. Typically, this will be a Move method. The idea is to move the control to the point at which the drop takes place (this doesn't happen automatically when the user drops the control).

That's all there is to it. However, one of the main limitations of the technique is that you can't drop the control outside its parent container (I think that's right; I'm going from memory here).

Also, if the control in question is a button, it doesn't respond to normal mouse clicks - only to dragging and dropping. The simple solution to that is to use a shape or a container instead of a button.

I hope this helps. Come back if you have any specific questions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I just ask you to check this example. The main code you need from it is Setting .Moverbars=.T., of course you also need to know hoe to iterate list items and set and get values, which also is included.

This boring minigame asks you to sort 10 numbers and will tell you, when every item is sorted.
Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


**************************************************
*-- Form:         form1 (c:\users\olaf\documents\visual foxpro projects\forms\moverbars.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   01/31/15 11:54:01 AM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 325
	Width = 253
	DoCreate = .T.
	Caption = "Form1"
	*-- XML Metadata for customizable properties
	_memberdata = ""
	Name = "Form1"


	ADD OBJECT list1 AS listbox WITH ;
		Height = 277, ;
		Left = 13, ;
		MoverBars = .T., ;
		Top = 36, ;
		Width = 228, ;
		Name = "List1"


	ADD OBJECT label1 AS label WITH ;
		BackStyle = 0, ;
		Caption = " Sort the items in numerical order", ;
		Height = 17, ;
		Left = 12, ;
		Top = 12, ;
		Width = 228, ;
		Name = "Label1"


	PROCEDURE checkorder
		Local lnVal, lnItemNo, llSorted
		lnVal = 0
		llSorted = .T.
		With Thisform.List1
		   For lnItemNo=1 To .ListCount
		      If lnVal>Val(.List(lnItemNo))
		         llSorted = .F.
		         Exit
		      Endif
		      lnVal = Val(.List(lnItemNo))
		   Endfor
		   If llSorted
		      .ItemBackColor = Rgb(80,255,80)
		      Messagebox("You made it!",0,"Congrats!")
		   Else
		      .ItemBackColor = Rgb(255,80,80)
		   Endif
		Endwith
	ENDPROC


	PROCEDURE list1.InteractiveChange
		Thisform.CheckOrder()
	ENDPROC


	PROCEDURE list1.Init
		=Rand (-1)
		Local lnCount
		For lnCount = 1 To 10
		   This.AddItem(Transform(Int(Rand()*100)))
		Endfor
		Thisform.CheckOrder()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

Bye, Olaf.
 
Forgot to explain a little bit. First time participants need a tutorial teaching how to move items up and down. Instead of drag and drop anywhere at the item you have a handle at the left side, these little buttons show a updown arrow when clicking, which indicates how you move them, but it's not obvious from the first place. On the other side a form with 10 buttons also does not intuitively suggest you can drag and drop them, unless you indicate it in some tutorial.

Bye, Olaf.
 
I have found the "Allow users to drag and drop" example but I'm not sure how I can implement that as yet. I'll post back when I find the right avenue.

Cheers guys

Thank you

Steve
 
Hey Olaf

That's a very interesting concept you have posted and appears to be quiet an easy way for users to click and drag upwards or downwards.

I'm going to see if I can develop that and I'll post back when I can.

Appreciate the input

Thank you

Steve
 
I have found the "Allow users to drag and drop" example but I'm not sure how I can implement that as yet.

Steve,

Let me give you a very simple example of what I had in mind.

You might well find Olaf's method more appropriate, so by all means stay with that, but I'll explain this other option for you to consider.

1. Place any control on a form. (I use an image when demonstrating this, but a label or button would also be good.)

2. Set its DragMode property to 1.

3. In the DragDrop event of the form (not the image), add this code:

[tt]LPARAMETERS oSource, nXCoord, nYCoord
oSource.Move(nXCoord, nYCoord[/tt])

4. Run the form. You now should be able to drag the image control with the mouse.

The slight snag is that, when you drop the image, it is not in exactly the right place. It is a little to the right and down from where you expect it to appear. That's because nXCoord and nYCoord represent the centre of the drop point, but the Move method requires the top-left corner of the drop point. But that's easy to fix:

Code:
LPARAMETERS oSource, nXCoord, nYCoord

LOCAL lnXDrop, lnYDrop

* Calculate top-left corner of drop point
lnXDrop = nXCoord - (oSource.width / 2)
lnYDrop = nYCoord - (oSource.height / 2)

oSource.Move(lnXDrop, lnYDrop)

As I said earlier, this is a highly simplified example. You can do anything you like in the DragDrop method. You don't have to move the object. For example, you might use the technique to let the user delete something from your form, in which case you could let them drop it on a trashcan icon, and then delete the object.

This is just something for you to consider.

Mike






__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike, I'm still working on this and I'll post back

Thank you

Steve
 
Hello

Just thought I would post back as I was unable to progress this and another colleague has now managed to create what we were after in flash.

I appreciate your time and posts on this thread

Thank you

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top