locked
Get x,y Co-ordinates on Pointer Press In WinStore XAML/C# App RRS feed

  • Question

  • I want to get x,y co-ordinates of pointer pressed (mouse/pen/touch) in a Windows Store Blank XAML/C# app. I know how to do this in WinForms, but unfortunately Pointer and Controls Classes are not same in WinStore Apps. Looked through several articles, but I found them all in WinForms. 
    • Edited by Talha Hasan Saturday, March 8, 2014 11:16 AM
    Saturday, March 8, 2014 10:07 AM

Answers

  • Hi Talha

    I guess it would help you;

        private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                e.GetCurrentPoint(MyButton);
            }

    Regards

    Arafat

    • Marked as answer by Anne Jing Monday, March 17, 2014 1:57 AM
    Sunday, March 9, 2014 6:20 AM
  • Hi,

    You can use GetCurrentPoint which is the method of PointerRoutedEventArgs that comes to your event handler. And if you pass in a control as a parameter, it will give you the Point of interaction relative to the control:

    Here is an example event handler:

          private void Image_PointerPressed_1(object sender, PointerRoutedEventArgs e)
            {
                Point p = e.GetCurrentPoint(sender as Image).Position;
                XCoord.Text = p.X.ToString();
                YCoord.Text = p.Y.ToString();
            }
        }
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Monday, March 17, 2014 1:57 AM
    Monday, March 10, 2014 6:39 AM

All replies

  • Hi Talha

    I guess it would help you;

        private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                e.GetCurrentPoint(MyButton);
            }

    Regards

    Arafat

    • Marked as answer by Anne Jing Monday, March 17, 2014 1:57 AM
    Sunday, March 9, 2014 6:20 AM
  • Hi,

    You can use GetCurrentPoint which is the method of PointerRoutedEventArgs that comes to your event handler. And if you pass in a control as a parameter, it will give you the Point of interaction relative to the control:

    Here is an example event handler:

          private void Image_PointerPressed_1(object sender, PointerRoutedEventArgs e)
            {
                Point p = e.GetCurrentPoint(sender as Image).Position;
                XCoord.Text = p.X.ToString();
                YCoord.Text = p.Y.ToString();
            }
        }
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Monday, March 17, 2014 1:57 AM
    Monday, March 10, 2014 6:39 AM