C#.Net:How to find the distance between two points clicked using mouse Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepshetty
    New Member
    • Aug 2008
    • 7

    C#.Net:How to find the distance between two points clicked using mouse Button

    hi All,
    Im new to .NET ... I need your help.. I just wanted to know if their is any method or event in .NET to find the distance between two points clicked using a mouse button.... I working on a web form and i need this action to happen over an GIF image file... I hope this is clear and somebody will help me out...

    Thank You,
    Sandeep.
  • sandeepshetty
    New Member
    • Aug 2008
    • 7

    #2
    C#.Net:How to find the distance between two points Using Mouse Button

    Hi...
    As im new to .Net .. I just wanted to know if their is any "event or method" in C#.net to find the DISTANCE between the two Points....

    Say for example:" I have two points on a web form and i need to find its distance by Dragging the MOUSE BUTTON from one Point to the Other Point..."

    Please let me know how.??.

    Regards ,

    Sandeep.

    Comment

    • JamieHowarth0
      Recognized Expert Contributor
      • May 2007
      • 537

      #3
      Hi there,

      It can be done with client-side Javascript but not C# (or so I believe).

      Anyone with prior experience on this kind of problem before?

      medicineworker

      Comment

      • IanWright
        New Member
        • Jan 2008
        • 179

        #4
        Originally posted by sandeepshetty
        Hi...
        As im new to .Net .. I just wanted to know if their is any "event or method" in C#.net to find the DISTANCE between the two Points....

        Say for example:" I have two points on a web form and i need to find its distance by Dragging the MOUSE BUTTON from one Point to the Other Point..."

        Please let me know how.??.

        Regards ,

        Sandeep.
        I think medicineworker is right. You need to look at JavaScript events, store the x,y values upon a MouseDown event to start with. Then using simple pythagoras calculate the distance either everytime a MouseMove event is fired, or the MouseUp event...

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Well regardless of where you do it, the distance between two points is computed with like an elementary math formula, The Distance Formula

          Comment

          • JamieHowarth0
            Recognized Expert Contributor
            • May 2007
            • 537

            #6
            Yes, simple Pythag will do it, and handling of two events - onmousedown to trap the pixel co-ordinates of the beginning of the "drag" motion, and onmouseup to trap the pixel co-ords of the end of the "drag".

            As IanWright and Plater mentioned, then do simple trigonometry to deduce the distance between the two points. Bear in mind you'll only have a measure of how many pixels the distance is - to make it useful in context (for example, dragging and dropping walls on a virtual "house" application for a website), then use a "scale" and add a metric to multiply the end result in pixels (i.e. 100px = 5 metres).

            medicineworker

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              But as others said, this must be done client-side, not in C#. To put it into context, the page would have to PostBack to the server on the mouse down to send the coordinates, but since there was a postback, it would never know when the mouse up happened.

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Please do not double post. If you have lost your thread, you can find it through the "My Subscriptions" link near the top of the page. If you feel like your thread has been neglected, you can reply to the original thread to "bump" it back to the top. We ask that you wait about 24 hours before bumping your thread. Double posting confuses everyone, and potentially duplicates work and help.

                Please read the Posting Guidelines.

                I have merged your threads.

                MODERATOR

                Comment

                Working...