0

I need to get mouse position relatively to my listbox, in event handler i get window relative coordinates, how to translate it into control relative?

EDIT:

private void OnMouseMove(object sender, MouseEventArgs e)
{
    Point mousePos = e.GetPosition(null);
    ...
}

So, it looks like it is mouse position i need, but really it could change for the moment.

Yola
  • 18,496
  • 11
  • 65
  • 106

1 Answers1

0

Just use the Mouse.GetPosition(RealitiveUIElement) method

Here it is outlined on the MSDN Site http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.getposition.aspx

// displayArea is a StackPanel and txtBoxMousePosition is 
// a TextBox used to display the position of the mouse pointer.
Point position = Mouse.GetPosition(displayArea);
txtBoxMousePosition.Text = "X: " + position.X +
    "\n" +
    "Y: " + position.Y;
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111