Search code examples
c#wpfcomputer-visionmouseoveronmousemove

How to check Mouse over all button WPF


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


Solution

  • 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>