Moving a graphic

jayclarke112

New member
Joined
Jan 31, 2006
Messages
3
Programming Experience
Beginner
Hi there, am pretty much brand new to vb.net and am wondering if the following is possible;

If I can place an image in a form, and when this image is clicked it automatically moves (slides) to a new location. I did this a long while back in vb6, whereby i kept erasing, moving and redrawing the image but I have heard vb.net has some cool features like animated images. Maybe there is a more elegent solution now?

Also, any ideas given would they work on windows mobile 5.0?

Thanks for the help and advice
 
The easiest way i can think would be to put them in a picture box and on clicking them move the picture box by changing the top and left.

Or if you are doing a shuffle type game you can just make one picture box for each space and swap the appropriate images

And yes you can do animation and move images but handling when they get clicked, or even figureing out that they have been clicked as they move across the screen is kind of tough
 
to truly do this like a programmer would mean drawing the image directly on the form, defining a region and then, in the OnClick event of the form, you would have to check if your region (it would be best if it were a rectangleF structure) contained the point defined by the mouse coordinates and so on (sorry though, I don't have vb in front of me right now, so no source code).

If you were to use shroomy's solution (which, by the way, is the easiest, but you won't learn much of GDI+ with it), one question still remains: do you want to move the image while holding the mouse? or just click and let it move?

if you want to drag the image, get a picturebox, put an image in it, then do the following:

Declare Ansi Function ReleaseCapture Lib "user32" () As Integer
Declare Ansi Function SendMessage Lib "user32" (hWnd As Integer, Msg As Integer, wParam As Integer, lParam As Integer) As Integer
Const WM_NCLBUTTONDOWN As Short = &HA1S

Sub MovePictureBox()
ReleaseCapture()
SendMessage(PictureBox1.Handle.ToInt32, WM_NCLBUTTONDOWN, 2, 0&)
End Sub

And in the MouseMove event of the picturebox just write:

MovePictureBox()

If you run your program, you should be able to move your PictureBox freely within the form.
I'm probably the biggest idiot by giving you this source code, because, if you have experience with vb6, you most likely know a wide set of WinAPI functions. Anyway, others may find it new...
 
Back
Top