15,901,426 members
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

Solution 1

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.)

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?

Solution 2

You might get a clue or two here[^].

Solution 3

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 :)

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)

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 30 Graeme_Grant 20 OriginalGriff 10 Richard MacCutchan 10 Greg Utas 10
 Pete O'Hanlon 1,490 OriginalGriff 1,142 Richard MacCutchan 335 Dave Kreskowiak 320 Richard Deeming 300

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