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
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Krishnaraj LPosted Jun 6, 2006, 5:42 AM
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.