[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cursor position Error

Posted on 2008-11-05
2
Medium Priority
?
360 Views
Last Modified: 2013-12-17
hi,
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

0
Comment
Question by:Ameerh24
2 Comments
 
LVL 1

Expert Comment

by:elvirbrk
ID: 22885516
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.
0
 
LVL 8

Accepted Solution

by:
bhmahler earned 1500 total points
ID: 22886347
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question