如何实现某些按钮在移动鼠标时出现一段时间,然后在鼠标静止时消失?
我使用 MouseMove
事件来检测鼠标移动,因此我可以更改按钮的可见性。鼠标停止移动后,按钮仍然在那里,因为我不知道如何以及在哪里计算时间以使这些按钮再次不可见。
这些按钮是全屏视频播放器上的控件,因此也欢迎任何其他想法。
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
timer.Stop();
button1.Visibility = Visibility.Hidden;
button2.Visibility = Visibility.Hidden;
}
private void mediaElement1_MouseMove(object sender, MouseEventArgs e)
{
if (!timer.Enabled)
{
timer.Enabled = true;
return;
}
if (timer.Enabled)
{
timer.Interval = 2000;
timer.Start();
button1.Visibility = Visibility.Visible;
button2.Visibility = Visibility.Visible;
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
}
}
I used MouseMove
event to detect mouse movement, so I could change the visibility of my buttons. After the mouse has stopped moving, the buttons are still there, because I don't know how and where to count for the time to make those buttons invisible again.
Those buttons are controls on video player in full screen, so any other idea is also welcomed.
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
timer.Stop();
button1.Visibility = Visibility.Hidden;
button2.Visibility = Visibility.Hidden;
}
private void mediaElement1_MouseMove(object sender, MouseEventArgs e)
{
if (!timer.Enabled)
{
timer.Enabled = true;
return;
}
if (timer.Enabled)
{
timer.Interval = 2000;
timer.Start();
button1.Visibility = Visibility.Visible;
button2.Visibility = Visibility.Visible;
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择是使用某种形式的计时器,例如
定时器
类。然后,您可以连接到Elapsed< /code>
事件并使用其中的处理程序来计算经过的时间。一旦达到一定的时间阈值,您就可以隐藏按钮。因此,代码步骤的示例如下:
Timer.Elapsed
事件的时间。Your best bet would be to utilize some form of timer, such as the
Timer
class. You can then hook up to theElapsed
event and use the handler inside there to count the time elapsed. Once you reach a certain time threshold, you can then hide the buttons. So an example of the code steps would be something like:Timer.Elapsed
event.