c# winform:点击标签后如何忽略鼠标离开事件?

c# winform : How to ignore the event of leaving the mouse after clicking on the label?

程序实际上是在用户点击鼠标离开控件后执行鼠标离开事件,如果我不想运行执行点击时的鼠标离开事件

    private void LblNoeMelk_MouseHover(object sender, EventArgs e)
    {
        HoverColor.LblHover(LblNoeMelk);
    }

    private void LblNoeMelk_MouseLeave(object sender, EventArgs e)
    {
        
        LeaveColor.LblLeave(LblNoeMelk);
    }

    private void LblNoeMelk_Click(object sender, EventArgs e)
    {
        HoverColor.LblHover(LblNoeMelk);
    }

您可以使用变量来检查 当取消点击事件为 运行.

时检查该变量

比如当按钮被点击时,flag的值为1,当我们取消点击时,如果flag的值为1,则什么都不做。

注意:将unclick方法末尾的flag值改为0。

在代码中实现@Saeed 解决方案-

bool isLabelClicked = false;

private void LblNoeMelk_MouseHover(object sender, EventArgs e)
    {
        HoverColor.LblHover(LblNoeMelk);
    }

    private void LblNoeMelk_MouseLeave(object sender, EventArgs e)
    {
        if(isLabelClicked ==true)
        {
              isLabelClicked = false;
              return;
        }
        LeaveColor.LblLeave(LblNoeMelk);
    }

    private void LblNoeMelk_Click(object sender, EventArgs e)
    {
        HoverColor.LblHover(LblNoeMelk);
        isLabelClicked = true;
    }