-
February 2nd, 2010, 09:47 AM
#1
Jumping mouse coordinates
Hello,
I've got a question regarding the coordinates I get for my mouse position. I'm rather rusty at the moment with my C# and I've started a new project to pick it back up.
I'm currently trying to move a pictureBox and I'm using the onMouseMove event to trigger the update for my mouse coordinates. But the coordinates I get from my mouse are somehow jumping between values.
I'm guessing this has something to do with the different forms, but I'm not sure. I'm hoping anyone can clear this out for me.
I'm using .net framework 3.5 and using VS2008. If more information is needed, please ask!
-
February 2nd, 2010, 10:20 AM
#2
Re: Jumping mouse coordinates
I'm guessing this has something to do with the different forms
This is kind of an important detail... can you explain it more? Are you trying to drag a picture box from one form to another? Are you using coordinates relative to each form?
-
February 2nd, 2010, 10:23 AM
#3
Re: Jumping mouse coordinates
Basically I have the main form and a panel. Inside the panel I have the pictureBox and I'm trying to move the picturebox.
Code:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pictureBox1.Location = new Point(e.X, e.Y);
textBox1.Text = "X: " + e.X + " Y: " + e.Y;
Refresh();
}
}
-
February 2nd, 2010, 10:26 AM
#4
Re: Jumping mouse coordinates
I'd capture MouseDown/MouseUp and cache the coordinates.
On MouseDown, capture the X/Y location, and on MouseUp, capture the X/Y location and set the picturebox to the new location if it's different.
-
February 2nd, 2010, 10:37 AM
#5
Re: Jumping mouse coordinates
That would probably work, but I'm more interested in making the pictureBox move instead of just change location by a flash.
-
February 2nd, 2010, 02:29 PM
#6
Re: Jumping mouse coordinates
I got it working myself in a completely different way. But thanks for the thoughts anyway!
Greetz Wiizle
-
February 3rd, 2010, 12:38 AM
#7
Re: Jumping mouse coordinates
Originally Posted by Wiizle
I got it working myself in a completely different way.
would you share your solution with us?
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|