将鼠标移到控件的ScrollBar上时,将触发MouseLeave事件 [英] MouseLeave event fires when moving over control's ScrollBar

查看:192
本文介绍了将鼠标移到控件的ScrollBar上时,将触发MouseLeave事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于无法解决问题,我正在重新发布此问题(原始的这里).

I am reposting this question due to inability to solve the problem (original here).

在TreeView,ListBox中,或者从我的Google看来,它使用ScrollBar搜索任何内容,因此ScrollBar不被视为控件的一部分.

In the TreeView, ListBox, or it seems from my google searches anything with a ScrollBar, the ScrollBar is not considered a part of the control.

我有一个要放入自定义控件的TreeView,它是Dock Fill.因此,它就像一个自定义的TreeView,它具有我们所有的逻辑,可以在一处对其进行管理.

I have a TreeView that I'm putting into a custom control, and it's Dock Fill. So there it acts as a custom TreeView which has all our logic to manage it in one place.

在程序的某些部分中,我们基于MouseEnter事件将其滑出,并在MouseLeave事件中将其滑回,但是我们目前正在使用第三方库的TreeView进行替换,<

In parts of our program we slide it out based on a MouseEnter event, and slide it back in on a MouseLeave event, however we are currently using a 3rd party library's TreeView for this, which I have been tasked with replacing.

因此,我已将所有内容移至Windows TreeView,但找不到找到可靠捕获MouseLeave的方法-仅当它离开整个TreeView(包括滚动条)时.

So I've moved everything over to the Windows TreeView, but can not find a way to reliable capture the MouseLeave -only- if it leaves the entire TreeView, scrollbar included.

我已经看到了一种棘手的解决方案,将其包装在具有几个像素的面板中并捕获面板的MouseLeave,但是我很难相信这是Microsoft在这种情况下想要我们做的.

I've seen one hackish solution of wrapping it in a panel with several pixels and capturing the MouseLeave of the panel, but I hardly believe this is what Microsoft had intended us to do in this situation.

简而言之:

ScrollBar不会为控件触发MouseEnter或MouseLeave,由于用户无法使用ScrollBar,这使得使用MouseEnter/MouseLeave滑出控件不可用.

处理这种情况的首选方式是什么?

What is the preferred way to handle this situation?

在上一个问题中,我被建议使用Spy ++,并尝试附加到WndProc()来处理ScrollBar的MouseEnter/MouseLeave.

In the previous question I was given the advice to use Spy++ and attempt to attach to WndProc() to handle MouseEnter/MouseLeave for the ScrollBar.

但是,这不起作用,因为Spy ++显示的消息未在窗体级别或控件级别在WndProc()中触发.好像.NET看不到ScrollBar.

This however did not work as the messages Spy++ showed were not firing in the WndProc() at form level, or control level. It's as if .NET just can't see the ScrollBar.

对于这样一个简单的请求,使用WndProc()似乎也不切实际,是否还有其他方法可以做到这一点,或者如果WndProc()是唯一的方法,那么有人真的能够做到这一点并向我展示如何实现吗?

Using WndProc() also seems unrealistic for such a simple request, is there any other way to do this, or if WndProc() is the only way, has anyone actually been able to achieve this and show me how?

推荐答案

对此没有干净的解决方案.您的面板操作也不起作用,当用户快速移动鼠标时,它将完全被忽略.

There is no clean solution for this. Your panel trick doesn't work either, it will be completely missed when the user moves the mouse quickly.

平底锅.一旦获得MouseEnter,就启动一个200毫秒的计时器.在滴答"事件中,检查鼠标是否仍悬停在树视图上.例如:

Punt. Once you get MouseEnter, start a 200 msec Timer. In the Tick event, check if the mouse is still hovering the tree view. For example:

    private void treeView1_MouseEnter(object sender, EventArgs e) {
        timer1.Enabled = true;
        treeView1.Width = 220;
    }

    private void timer1_Tick(object sender, EventArgs e) {
        Point pos = treeView1.PointToClient(Cursor.Position);
        if (!treeView1.DisplayRectangle.Contains(pos)) {
            timer1.Enabled = false;
            treeView1.Width = 50;
        }
    }

Application.Idle事件的工作太顺便了,只是有点尴尬.

The Application.Idle event works too btw, just a wee bit more awkward.

这篇关于将鼠标移到控件的ScrollBar上时,将触发MouseLeave事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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