• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

Cursor position Error

I have have developed an application which is working fine in my laptop (which has a wide-screen 15.4 in)
and I have taken this application to another PC (which has a 17 in screen)
now I have user-friendly button which is working in my laptop but not in PC .. what I am doing is that there is a picture box control changing it's image depending on the cursor position that I put it in my code ..
now is there any or equation that I can do to avoid changing the absolute position values ?
here is a code sample:
private void WindowStatePicBox_MouseMove(object sender, MouseEventArgs e) 
            if (!isPressed)
                if (((Cursor.Position.X >= 933) && (Cursor.Position.X <= 975)) && (Cursor.Position.Y <= 139))
                    WindowStatePicBox.Cursor.Image = global::FRSystem.Properties.Resources._2;
                if (((Cursor.Position.X >= 908) && (Cursor.Position.X < 933)) && (Cursor.Position.Y <= 139))
                    WindowStatePicBox.Image = global::FRSystem.Properties.Resources._3;
                if (((Cursor.Position.X < 908) || (Cursor.Position.X > 975)))
                    WindowStatePicBox.Image = global::FRSystem.Properties.Resources._1;
                if(Cursor.Position.Y > 139)
                    WindowStatePicBox.Image = global::FRSystem.Properties.Resources._1;

Open in new window

1 Solution
I think that MouseEventArgs contains mouse location on form, so you can combine that with picture box location and size on form in order to achieve desired behavior. All those values are relative to form and not to screen. This way you don't need to use mouse absolute position.
you should be using e.Location not cursor position.  The mouse eventargs contains the location of the mouse in respect to your form and controls.  when using Cursor.Position you need to use your control and call PointToClient with the position.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now