Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I was thinking about making a little app that calculated how long a distance you are moving with your mouse. The distance should not be in pixels, but in inches or meters.

But is this even possible? You cant convert pixels to inces, and different computers have different mouse settings etc.

Any good ideas? :)

Thanks!
Posted

Of course you can convert them. You may need to find the dpi of your monitor so that you can discover how many pixels consume an inch of monitor space. (And I don't think you're really interested in meters as much as you are in millimeters.)
 
Share this answer
 
Comments
lvq684 19-Aug-10 13:43pm    
Hmm ok.

Then lets say I have the user manually insert the size (in inches) of his monitor, and the resolution.
How would i then calculate the milimeters, when the user has moved lets say 1000 pixels, with his mouse?
You might get a clue or two here[^].
 
Share this answer
 
Thanks for your answers :)

It seems like the only most precise, easy (and clumsy) way, is to make the user measure the height and width of his monitor size with a measuring tape, and then calculate the distance from these data and the resolution.

Thanks :)
 
Share this answer
 
Comments
dojohansen 20-Aug-10 3:05am    
You can obtain the DPI programmatically, thus requiring your user to do nothing at all to achieve this. In a WinForms/C# context:
float x, y; // DPI in horizontal and vertical direction (tho they should be equal..)

using (var g = this.CreateGraphics())
{
x = g.DpiX;
y = g.DpiY;
}

The using statement is simply to ensure the Graphics is disposed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900