Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mouse co-ords from form when over pic 1

Status
Not open for further replies.

tomcoombs

Programmer
Aug 14, 2003
65
GB
I am trying to move a picture on a form when the mouse "drags" it. On form.mousemove the co-ord flow in nicley until I am over the picture a want to move (thus useless!)

The picture seems to be "on top" of the form, and thus no musemove event it called.

Damm annoying - any ideas?



Here the code if it hepls :




private void box_mousedown(object sender, System.Windows.Forms.MouseEventArgs e)
{
mousedown = true;

int MouseX = UserControl3.MousePosition.X;//X cordinate
int MouseY = UserControl3.MousePosition.Y;//Y Cordinate
if ((MouseX>box.Location.X) && (MouseX<(box.Location.X+box.Size.Width)) &&
(MouseY>box.Location.Y) && (MouseY<(box.Location.Y+box.Size.Height)))
{
MessageBox.Show(&quot;Not In Box!&quot;);
inboxques = false;}
else
{//ie in the box
inboxques = true;
}
}

private void box_mouseup(object sender, System.Windows.Forms.MouseEventArgs e)
{
mousedown = false;
}

private void m(object sender, System.EventArgs e)
{

}

private void form1_mousemove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Console.WriteLine(&quot;Mouse move!&quot;+tmpcount);
tmpcount++;
if (mousedown == true)
{

//MessageBox.Show(&quot;X : &quot;+UserControl3.MousePosition.X);
//box.Location = new System.Drawing.Point(UserControl3.MousePosition.X-300, 16);
}

}


Thanks

Tom
 
i dont understand why you can't use the mouse move method. when i've done things like this before, i've written code thus:

Point dragFrom = new Point();

private void box_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e){
dragFrom.X = e.X; //keep a record of where the mouse is
dragFram.Y = e.Y; //you can use this to offset the box location
}

private void box_MouseMuve(object sender, System.Windows.Forms.MouseEventArgs e){
if(e.Button == MouseButtons.Left){
box.Location.X = e.X - dragFrom.X; //i'm not 100% sure you can access Location.X directly
box.Location.Y = e.Y - dragFrom.Y; //if not, just alter location my creating a new Point object
}
}

____________________________________________________
If you like a post, show you care by giving it a star.
 
Thanks Sean,


The problem with that is that the &quot;box&quot; is a picturebox, and thus when over it form.mousermoves happen :-(

Tom
 
i've never heard of a PictureBox's MouseMove event not working. i remember making a similar thing from a PictureBox myself and it worked fine. in fact, i've got the code open right now.


MouseMove += new System.Windows.Forms.MouseEventHandler(this.extraMouseMove);

private void box_MouseMuve(object sender, System.Windows.Forms.MouseEventArgs e){
MessageBox.show(&quot;mouse movement recognised&quot;);
}


are you sure you can't get any love out of a piece of code like this??

____________________________________________________
If you like a post, show you care by giving it a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top