简体   繁体   English

如何在所有按钮WPF上检查鼠标

[英]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 在下图中,用户在第1侧的按钮上方进行操作,然后以箭头方式在第2侧进行移动,我的问题是如何检查用户在操作上进行此操作以进行特定操作
Can give make link or bit of code help me to make that? 可以给make链接或一段代码来帮助我做到这一点吗?


在11面然后2面

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.. 现在,此位置在画布上,因此将告诉您从哪个侧面鼠标进入或离开。

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 : 和XAML:

  <Button Width="100" x:Name="MyButton" Height="30" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave" >HoverMe</Button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM