Draging an image Control
Hi,
I have several Rectangles/Images on a Form,I want the user to be able to move/drag them around with the Mouse
(one at a time of course) Like in a JigSaw
Thanx
GopinathMenon
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Krishnaraj L153 reputationPosted Jun 6, 2006, 1:42 AM EDT
If you want move an image/rectangle based on the users click, you need to store the co-ordinates of all objects in Rectangle arrays and whenever user is clicking on one of the objects, check whether the mouse pointer is in any of the objects placed on your form.
private
void MainScreen_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e){
if ( m_rectImage1.Contains ( e.X, e.Y ) == true ) // clicked on one of the images{
// add your code here
// use a flag to identify which object is clicked
}
...
}
Then when the mouse button is released change the co-ordinates of your moved image and draw it with the new co-ordinates.
You can even do this whenever user is dragging the mouse.
Hope this helps.