×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

i want to move an image to any location i want on the form
2

i want to move an image to any location i want on the form

i want to move an image to any location i want on the form

(OP)
Hi,
i would like to know what is the trick to move an image i have in my form, from the default location(the actual location when the form load) i have it now, to any other location desired by the user, i know we need to use image property Mousemove and have nButton =1 for it for the left click to move the image but i need something else to be added to code, to just move it around and located where i want, can anyone advise please ?
Thanks a lot

RE: i want to move an image to any location i want on the form

It's easier than that. Just set the image's DragMode property to 1. That will let the user drag it around the form using the mouse. When the user drops the image, its DragDrop event fires. That will tell you the location of the point where the image has been dropped. You them use that information to programmatically move the image to that new location.

At its simplest, the code in the DragDrop looks like this:

CODE -->

LPARAMETERS oSource, nXCoord, nYCoord
oSource.Move(nXCoord, nYCoord) 

CORRECTION: The above code should go in the DragDrop event of the form, not the image as stated above. Apologies.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: i want to move an image to any location i want on the form

Ernesto,

You have to control the drag and drop of the image object.

This is a demo that drags and drops a shape, but it can be used with an image as well. You can see that you'll have to add extra code if you want to prevent some areas of your form to be used as a drop spot for the image.

CODE --> VFP

LOCAL Test AS DragNDropper

m.Test = CREATEOBJECT("DragNDropper")
m.Test.Show(1)
m.Test = .NULL.

DEFINE CLASS DragNDropper AS Form

	ADD OBJECT NotOverMe AS Label ;
		WITH Top = 10, Left = 200, ;
		Caption = "Not over me!"

	ADD OBJECT OverMe AS Label ;
		WITH Top = 30, Left = 200, ;
		Caption = "Over me!"

	ADD OBJECT ABox AS Shape ;
		WITH Top = 10, Left = 10, ;
			BackColor = RGB(128, 0, 0), ;
			BorderColor = RGB(128, 128, 0), ;
			BorderWidth = 5, ;
			Height = 100, Width = 100, ;
			DragMode = 0, ;
			XStart = 0, YStart = 0

	FUNCTION ABox.MouseDown (MouseButton AS Integer, AddKey AS Integer, XCoord AS Integer, YCoord AS Integer)

		IF m.MouseButton = 1 AND m.AddKey = 0
			This.XStart = m.XCoord
			This.YStart = m.YCoord
			This.Drag(1)
		ENDIF

	ENDFUNC

	FUNCTION ABox.DragDrop (Source AS Object, XCoord AS Integer, YCoord AS Integer)

		Thisform.DragDrop(m.Source, m.XCoord, m.YCoord)

	ENDFUNC

	FUNCTION OverMe.DragDrop (Source AS Object, XCoord AS Integer, YCoord AS Integer)

		Thisform.DragDrop(m.Source, m.XCoord, m.YCoord)

	ENDFUNC

	FUNCTION DragDrop (Source AS Object, XCoord AS Integer, YCoord AS Integer)

		m.Source.Top = m.Source.Top + (m.YCoord - m.Source.YStart)
		m.Source.Left = m.Source.Left + (m.XCoord - m.Source.XStart)
		This.Refresh()

	ENDFUNC

ENDDEFINE 

RE: i want to move an image to any location i want on the form

Just to add ....

My method will work provided you are only dragging within a single container. If you just want to drag from one part of the form to another, that should be fine. It won't work if you want to drag from one form to another, or to or from a container within the form. In those cases, you would have to use OLE Drag and Drop, which is a little more complicated.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: i want to move an image to any location i want on the form

(OP)
Hi Mike,
i added the code provided but actually i when i drag the image, the image moves but once i release the mouse, the image comeback to the original location so actually it does not move to the location dragged, i just missing something else here ?
i just trying to move the image inside the form itself from one location to another in the same form

Thanks

RE: i want to move an image to any location i want on the form

Ernesto,

I made a small mistake in my original code. I have now corrected it. Please go back and copy the code again.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: i want to move an image to any location i want on the form

(OP)
Thanks Mike, it works, thanks atlopes

RE: i want to move an image to any location i want on the form

Just note this isn't working that flawless when you drag the image on a "crowded" part of the form (meaning: there already are other controls on it). And while that's not a big problem, because you'd also want to drag it to an empty space, a container or a pageframe is blocking the form's DragDrop event. Besides, you'd then want to let the image control not just change its coordinates but also its parent objhect to become whatever you dragged it onto.

The form designer often enough makes it easier to copy and paste a control, or cut and paste. After copy or cut you then first activate the target and paste.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: i want to move an image to any location i want on the form

One other point to keep in mind ....

The coordinates that you pass to the Move method (nXCoord, nYCoord) refer to the top-left corner of the image. That's fine. But the user might expect the drop point to match the position of the mouse pointer. So if the mouse is in the centre of the image during the drag, they might expect it to be dropped in such a way that the pointer is still in the centre when it is dropped.

This is probably not worth worrying about, but if it is an issue, you would need to adjust the coordinates to take it into account.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: i want to move an image to any location i want on the form

Just for the record,

Quote (Mike)

The coordinates that you pass to the Move method (nXCoord, nYCoord) refer to the top-left corner of the image. That's fine. But the user might expect the drop point to match the position of the mouse pointer. So if the mouse is in the centre of the image during the drag, they might expect it to be dropped in such a way that the pointer is still in the centre when it is dropped.
the demo above handles that case.

RE: i want to move an image to any location i want on the form

Quote (António)

the demo above handles that case

Quite right. You are adjusting the Top and Left of the object. That's better than using the Move method.

On a small point, António, you don't need to do a Refresh in the DragDrop event (unless you have some reason for doing so which is not connected to the drag-and-drop).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: i want to move an image to any location i want on the form

Quote (Mike)

On a small point, António, you don't need to do a Refresh in the DragDrop event

You're right, Mike, the Refresh() is unnecessary in the demo.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close