VB 2005 - Moving Stuff with the Mouse

This topic is 3815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm looking to put an object on the form, like a picture box, then be able to move the pointer over it, click and hold, drag it to another location on the form, and then release the mouse click to drop it in its new location. Kind of like a drag and drop function but no limitations on where it starts or where it drops. Is this a really tricky thing to do, or am I just missing a simple solution?

bump

Share on other sites
React to a mouse keydown event, and as long as there's no mouse keyup event, change the position of the object that's clicked on according to the mouse movement.

Your question is kind of vague: you didn't mention what language and environment you're working with, or for what purpose you need this, so I'm afraid I can't give a more specific answer than that.

Share on other sites
I'm working in Visual Basic 2005.

I'm working on a turn-based game and I need to click, drag, and move counters around a board. The counters will be picture boxes holding images of troops, tanks, etc.

bump

Share on other sites
Hey,
Captain P was pretty much on the money. I had a quick look and found a great example on msdn (which has a VB example).

Here

This example shows how to use mouse events to create a rectangle, so you can ignore the rectangle stuff and put in some location stuff instead.

in pseudo code (kinda) you'd do something like this in the Form1_MouseMove event:
if(dragging == true){ pictureBox1->Location.X = CurrentMousePosition.X; pictureBox1->Location.Y = CurrentMousePosition.Y;}

So read the article and see how you get on. I'm actually gonna try this tomorrow when i have time cos it's quite relavant to something i'm working on, so i'll let you know how I go (although i'm using C++, but you should be able to figure it out).

Something that'd be even cooler would be if you could make it 'dock', so when the location gets within certain bounds change the location to its docking position. Although i notice in your original post you want no limitations on where it drops, so maybe not :)

Share on other sites

This topic is 3815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.