如何解决事件延迟 [英] How to fix the event delay

查看:133
本文介绍了如何解决事件延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个学校项目制作一个桌子预订系统,我使用一个PictureBox列表来表示这些表格。
对于这些PictureBox我已经链接了一个悬停事件,并且当我悬停时,BackColor属性发生了变化。

  List<图片框> pb =新列表< PictureBox> {pictureBox1,pictureBox2,pictureBox3}; 

foreach(PictureBox p in pb)
{
p.BorderStyle = BorderStyle.Fixed3D;
p.BackColor = Color.White;
p.MouseHover + = new EventHandler(mouseOn);


private void mouseOn(object sender,EventArgs e)
{
((PictureBox)sender).BackColor = Color.Green;

$ / code>

一切都很好,除了当我将鼠标悬停时,它需要1第二次在事件被触发之前,是否有任何方法可以立即触发事件? 解决方案

如果你想立即触发事件,改为使用 MouseEnter 事件。通过设计,您的鼠标应该在 MouseHover 事件触发时保持静止一段时间。



em> SystemInformation.MouseHoverTime 会为 MouseHover 事件延迟。


I'm making a table reservation system for a school project, and I'm using a list of PictureBoxes to represent the tables. To these PictureBoxes I have linked a hover event, and when I hover the BackColor property is changed.

List<PictureBox> pb = new List<PictureBox> { pictureBox1, pictureBox2, pictureBox3};

foreach (PictureBox p in pb)
{
    p.BorderStyle = BorderStyle.Fixed3D;
    p.BackColor = Color.White;
    p.MouseHover += new EventHandler(mouseOn);
}

private void mouseOn(object sender, EventArgs e)
{
    ((PictureBox)sender).BackColor = Color.Green;
}

Everything works great, except that when I hover the mouse over, it takes 1 second before the event is triggerd, is there any way to trigger the event immidiately?

解决方案

If you want to trigger event immediately, use MouseEnter event instead. By design your mouse should stay stationary for some time for MouseHover event to fire.

BTW SystemInformation.MouseHoverTime holds that delay for MouseHover event.

这篇关于如何解决事件延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆