1

我正在创建自动打字应用程序。它是如何工作的: • 单击加载文本文件(文件将加载到richtextbox2) • 单击开始:(计时器将开始从richtextbox2 在richtextbox1 上键入代码) • 但是我遇到了问题:

(我已经使用了以下代码,但不适用于我)使用的代码:

RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox1.ScrollToCaret()

但是计时器值是 100 并且它与 count_ 代码一起使用:所以滚动条连续走 ▲▼▲▼▲▼(向上,向下,向上向下,...)如果我删除了此代码:那么滚动条不会向下自动地。如果手动完成,那么我会自动进入第一行,如果计时器正在进行中,则自动进入第一个单词......

所以请帮助我我能做什么

4

3 回答 3

2

将以下内容添加到您的代码中

RichTextBox1.HideSelection = False
于 2015-06-16T02:31:44.580 回答
1

为防止 RichTextbox 反弹效果▲▼ 当竖条在底部时,您可以将下面的 Class 粘贴到您的项目中并像这样使用它:

 RichTextBox1.Select(RichTextBox1.TextLength - 1, 1)

 If Not ScrollBarInfo.IsAtBottom(RichTextBox1) Then
    RichTextBox1.ScrollToCaret()
 End If

这是我对此处提供的代码的修改版本:如何知道 RichTextBox 垂直滚动条是否达到最大值?的@王王

#Region " Scrollbar Info "

Public Class ScrollBarInfo

    <System.Runtime.InteropServices.DllImport("user32")> _
    Private Shared Function GetScrollInfo(hwnd As IntPtr, nBar As Integer, ByRef scrollInfo As SCROLLINFO) As Integer
    End Function

    Private Shared scrollInf As New SCROLLINFO

    Private Structure SCROLLINFO
        Public cbSize As Integer
        Public fMask As Integer
        Public min As Integer
        Public max As Integer
        Public nPage As Integer
        Public nPos As Integer
        Public nTrackPos As Integer
    End Structure

    Private Shared Sub Get_ScrollInfo(control As Control)
        scrollInf = New SCROLLINFO()
        scrollInf.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(scrollInf)
        scrollInf.fMask = &H10 Or &H1 Or &H2 'SIF_RANGE = &H1, SIF_PAGE= &H2, SIF_TRACKPOS = &H10
        GetScrollInfo(control.Handle, 1, scrollInf)
    End Sub

    ' IsAtBottom
    Public Shared Function IsAtBottom(control As Control) As Boolean
        Get_ScrollInfo(control)
        Return scrollInf.max = (scrollInf.nTrackPos + scrollInf.nPage) - 1
    End Function

    ' IsAtTop
    Public Shared Function IsAtTop(control As Control) As Boolean
        Get_ScrollInfo(control)
        Return scrollInf.nTrackPos = 0
    End Function

    ' ReachedBottom
    Public Shared Function ReachedBottom(control As Control) As Boolean
        Get_ScrollInfo(control)
        Return scrollInf.max = scrollInf.nTrackPos + scrollInf.nPage
    End Function

    ' ReachedTop
    Public Shared Function ReachedTop(control As Control) As Boolean
        Get_ScrollInfo(control)
        Return scrollInf.nTrackPos < 0
    End Function

End Class

#End Region
于 2013-10-20T13:17:22.320 回答
1

当您在设计器中将 RichTextBox 的“隐藏选择”属性设置为False并使用AppendText ”方法时,RichTextBox 会在添加时自动向下滚动到底线。

博客。附加文本 ( dbcon.insertdata & Chr(13))

于 2015-08-06T09:00:14.187 回答