我正在创建自动打字应用程序。 它的工作原理:•点击加载文本文件(文件将加载到richtextbox2) •单击开始:(计时器将开始在richtextbox2上的richtextbox1上键入代码) •但在这里我遇到了问题:
(我已经使用了以下代码,但对我不起作用) 使用过的代码:
RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox1.ScrollToCaret()
但计时器值为100,它与count_代码一起使用: 所以如果我删除了这段代码,滚动条会连续走▲▼▲▼▲▼(向上,向下,向下,......) 然后滚动条不会自动关闭。 如果手动完成,那么如果计时器正在进行中,我会自动进入第一行,第一个单词...
所以,请帮助我,我能做什么
答案 0 :(得分:2)
将以下内容添加到代码中
RichTextBox1.HideSelection = False
答案 1 :(得分:1)
要防止RichTextbox反弹效果▲▼当垂直条在底部时,您可以将下面的类粘贴到您的项目中并使用它,如下所示:
RichTextBox1.Select(RichTextBox1.TextLength - 1, 1)
If Not ScrollBarInfo.IsAtBottom(RichTextBox1) Then
RichTextBox1.ScrollToCaret()
End If
这是我在此处提供的代码修改后的版本:@ {strong> King King 的<{3}}
#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
答案 2 :(得分:1)
当您设置RichTextBox&#34; 隐藏选择&#34;设计师错误的属性,并使用&#34; AppendText &#34;方法,RichTextBox将在追加时自动向下滚动到底线。
rtblog。 AppendText (dbcon.insertdata&amp; Chr(13))