I'm using the code below to see when the mouse right button is clicked, if it hits a target (Drawing
) or not.
Now If the mouse hits the target a message will be shown stating that we hit the target.
But where can I show a message that the target was NOT hit? VisualTreeHelper.HitTest()
doesn't seem to return a value indicating that the target was hit or not.
private void OnMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
var x = MousePos.RightDown.X;
var y = MousePos.RightDown.Y;
var hitRect = new Rect(x - 2, y - 2, 4, 4);
var geom = new RectangleGeometry(hitRect);
VisualTreeHelper.HitTest(Drawing,
null,
MyCallback,
new GeometryHitTestParameters(geom));
// Where should I put the MessageBox.Show("You did not hit the target");
// If I put it here it is displayed anyway
}
private HitTestResultBehavior MyCallback(HitTestResult result)
{
MessageBox.Show("You hit the target");
return HitTestResultBehavior.Stop;
}