当光标滚动富文本框时停止计时器 [英] Stopping a timer when cursor is scrolling richtextbox

查看:42
本文介绍了当光标滚动富文本框时停止计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 timer1 在光标位于富文本框内时停止,所以我已经尝试了一些事件,例如鼠标进入、鼠标按下和获得焦点以停止计时器,但是当我在时这些事件不起作用滚动富文本框.当光标位于富文本框内时,哪个事件允许我滚动并保持计时器 1 关闭?谢谢

I'm using a timer1 that stop when the cursor is inside of a richtextbox, so I tried already few events like Mouse enter, Mouse down and Got focus in order to stop the timer, but those are not working when I am scrolling the richtextbox. Which event allow me to scroll and keep timer 1 off as cursor is inside of richtextbox? Thanks

推荐答案

似乎没有简单的单一事件方法可以做到这一点.正如您所发现的,当您单击滚动条时,没有 EnterMouseEnter 事件.我认为以下应该做你想做的事情:

There appears to be no simple, one-event way to do this. As you have discovered, there is no Enter or MouseEnter event when you click the scrollbar. I think that the following should do the sort of thing you want:

Private isScrollingRtb As Boolean = False

Private Sub RichTextBox1_Enter(sender As Object, e As EventArgs) Handles RichTextBox1.Enter
    'The RTB received focus.
    Timer1.Stop()
End Sub

Private Sub RichTextBox1_Leave(sender As Object, e As EventArgs) Handles RichTextBox1.Leave
    'The RTB lost focus.
    Timer1.Start()
End Sub

Private Sub RichTextBox1_VScroll(sender As Object, e As EventArgs) Handles RichTextBox1.VScroll
    If Not ActiveControl Is RichTextBox1 Then
        'The user scrolled the RTB while it did not have focus.
        Timer1.Stop()
        isScrollingRtb = True
    End If
End Sub

Private Sub Form1_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
    If isScrollingRtb Then
        'The user left the RTB after scrolling it without focus.
        Timer1.Start()
        isScrollingRtb = False
    End If
End Sub

当用户单击滚动条时,会引发 VScroll 事件,因此您可以在该事件上Stop Timer.问题在于决定何时再次Start.在此示例中,我选择在鼠标指针下一次移过表单本身时执行此操作.

When the user clicks the scrollbar, the VScroll event is raised, so you can Stop the Timer on that event. The problem is deciding when to Start it again. In this example, I have chosen to do so when the mouse pointer next goes over the form itself.

这篇关于当光标滚动富文本框时停止计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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