-1

I try to implement way to check if the mouse over all button sides, as the mouse over the left side then the right side if the user make that make specific action
in the following image the user over button in side 1 then move in arrow way and over side 2, my problem how to check the user make this movement over the action to make specific action
Can give make link or bit of code help me to make that?


Over side 11 then side 2

mbugr
  • 322
  • 1
  • 4
  • 23
  • 1
    _[How do I ask a good question?](http://stackoverflow.com/help/how-to-ask)_ –  Mar 25 '15 at 15:02
  • Have you tried any code? It's hard to tell what you want from your question, some sample code would help everyone give you the answer you're looking for – amura.cxg Mar 25 '15 at 15:05
  • 1
    Look into the `MouseEnter` and `MouseLeave` events, and you can probably get the position the mouse enters/leaves compared to the button and go from there. – Rachel Mar 25 '15 at 15:10

2 Answers2

1

well you can do something like this for mouse enter and leave

<Canvas  x:Name="Canvas" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,9,6,0">
    <Button Canvas.Top="0" Canvas.Left="0" x:Name="button" Width="100" MouseEnter="Butt_OnMouseEnter" Height="200"/>
</Canvas>

and in handler

private void Butt_OnMouseEnter(object sender, MouseEventArgs e)
{
    var position = e.GetPosition(Canvas);
}

now this position is wrt to canvas hence will tell you which side mouse entered or left from..

Muds
  • 4,006
  • 5
  • 31
  • 53
1

It should be something like that :

 protected Point TouchStart;
        private void UIElement_OnMouseEnter(object sender, MouseEventArgs e)
        {
            TouchStart = e.GetPosition(this);
            MyButton.Background = Brushes.Red;

        }
    private void UIElement_OnMouseLeave(object sender, MouseEventArgs e)
    {
            var touch = e.GetPosition(this);

        if (touch.X >= (TouchStart.X + 99)) //button width here

        {
            MyButton.Background = Brushes.Aquamarine;
        }
    }

And XAML :

  <Button Width="100" x:Name="MyButton" Height="30" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave" >HoverMe</Button>
Dragos Stoica
  • 1,753
  • 1
  • 21
  • 42