CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    .Net 3.5
    Posts
    4

    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!

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    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?

  3. #3
    Join Date
    Feb 2010
    Location
    .Net 3.5
    Posts
    4

    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();
                }
            }

  4. #4
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    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.

  5. #5
    Join Date
    Feb 2010
    Location
    .Net 3.5
    Posts
    4

    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.

  6. #6
    Join Date
    Feb 2010
    Location
    .Net 3.5
    Posts
    4

    Re: Jumping mouse coordinates

    I got it working myself in a completely different way. But thanks for the thoughts anyway!

    Greetz Wiizle

  7. #7
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Jumping mouse coordinates

    Quote Originally Posted by Wiizle View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured