Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:00:36+00:00 2026-06-16T06:00:36+00:00

I need to calculate the distance between two places the mouse was clicked on

  • 0

I need to calculate the distance between two places the mouse was clicked on the screen.

target(x & Y) & source(X & Y) are populated on the mouse move event (e.X & e.Y)

I have distance = Math.Sqrt(Math.Pow(targetX - sourceX, 2) + Math.Pow(targetY - sourceY, 2));

This gives me a result but if I’m honest I am not sure what unit the measurement is in or how to convert it. How can I convert that result in a meaningful result such as cm’s or inches? I’m guessing I will need to take the screen res into account?

Update
Im just killing time really. Not looking for an excellent solution just something that works. It will only last a day or two.

Here is the MoveMove event and the call made. Should have posted it all before to be clearer.

    private void HookManager_MouseMove(object sender, MouseEventArgs e)
    {

        labelMousePosition.Text = string.Format("x={0:0000}; y={1:0000}", e.X, e.Y);
        AddDistance(Convert.ToDouble(e.X), Convert.ToDouble(e.Y));
    }

    private void AddDistance(double targetX, double targetY)
    {
        if (sourceX != 0 && sourceY != 0)
        {
            double distance = Convert.ToDouble(lblDistanceTravelled.Text);
            distance =+ Math.Sqrt(Math.Pow(targetX - sourceX, 2) + Math.Pow(targetY - sourceY, 2));
            lblDistanceTravelled.Text = distance.ToString();
        }
        sourceX = targetX;
        sourceY = targetY;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:00:38+00:00Added an answer on June 16, 2026 at 6:00 am

    You can get the “current DPI” via

    int currentDPI = 0;  
    using (Graphics g = this.CreateGraphics())  
    {  
        currentDPI = (int)g.DpiX;      
    }
    

    and then you can get

    double distanceInInches = distance/*InPixels*/ / currentDPI;
    

    However, the system’s DPI setting can’t really be relied upon to give a true conversion from pixel distances to on-screen-inch distances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate the distance (in meters and miles) between two coordinates given
I need to calculate distance between two locations in my android application. Then I
I need to calculate the distance between two points, but not in the regular
I need to calculate distance between two coordinates (lon,lat) on embedded system which doesn't
i need to calculate the distance between two CGPoint s. I refered this and
I need to calculate the Delta-E distance between two colors. The algorithm to do
How can use google map API to calculate the distance between two places based
I need to be able to calculate the minimum distance between two cities given
Hi I have the need to calculate the distance between two points having the
I need to calculate the distance between two addresses and I don't need a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.