Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know if the IPoint of the mouse position is hitting an IPolyline, I wrote this code, and was optimistic that it would work, but it always returns false.

  IPolyline poly1 = pc1 as IPolyline;

        IHitTest test = poly1 as IHitTest;
        if (test != null)
            int a = 0;
            int b = 0;
            bool c = false;
            double distance = 0;
            IPoint hitPoint = new PointClass();
            bool isHit = test.HitTest(mousepoint,
                                    ref distance,
                                    ref a, ref b, ref c);

share|improve this question
up vote 2 down vote accepted

I think you should probably not use esriGeometryHitPartType.esriGeometryPartNone, but choose a geometry part which you want to test.

In your case that would probably be esriGeometryHitPartType.esriGeometryPartBoundary, which means anywhere on the polyline.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.