Vb.net 将光标置于textbox/richtextbox的末尾

Vb.net 将光标置于textbox/richtextbox的末尾,vb.net,textbox,cursor,scrollbar,richtextbox,Vb.net,Textbox,Cursor,Scrollbar,Richtextbox,我正在创建自动键入应用程序。 工作原理:•单击加载文本文件(文件将加载到richtextbox2) •单击开始:(计时器将开始从richtextbox2在richtextbox1上键入代码) •但在这里我遇到了问题: (我已经使用了以下代码,但不适用于我) 使用的代码: RichTextBox1.SelectionStart = RichTextBox1.TextLength RichTextBox1.ScrollToCaret() 但计时器值为100,它与计数代码一起工作: 所以滚动条不断地

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

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

RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox1.ScrollToCaret()
但计时器值为100,它与计数代码一起工作: 所以滚动条不断地移动▲▼▲▼▲▼ (上、下、上、下……)如果我删除了此代码: 然后滚动条不会自动下降。 如果手动完成,则我进入第一行,如果计时器正在运行,则自动进入第一个字


因此,请帮助我如何防止RichTextbox反弹效应▲▼ 当垂直条位于底部时,您可以将下面的类粘贴到项目中,并按如下方式使用它:

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

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

这是我根据这里提供的代码修改的版本:of@King

#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
#区域“滚动条信息”
公共类ScrollBarInfo
_
私有共享函数GetScrollInfo(hwnd作为IntPtr,nBar作为整数,ByRef scrollInfo作为scrollInfo)作为整数
端函数
私有共享scrollInf作为新的SCROLLINFO
私有结构滚动信息
公共cbSize为整数
作为整数的公共fMask
公共最小值为整数
作为整数的公共最大值
作为整数的公共nPage
作为整数的公共非营利组织
公共nTrackPos为整数
端部结构
私有共享子Get_ScrollInfo(控件作为控件)
scrollInf=新的SCROLLINFO()
scrollInf.cbSize=System.Runtime.InteropServices.Marshal.SizeOf(scrollInf)
scrollInf.fMask=&H10或&H1或&H2'SIF\U范围=&H1,SIF\U页面=&H2,SIF\U轨迹位置=&H10
GetScrollInfo(control.Handle,1,scrollInf)
端接头
“我的屁股
公共共享函数IsAtBottom(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.max=(scrollInf.nTrackPos+scrollInf.nPage)-1
端函数
“伊萨托普
公共共享函数IsAtTop(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.nTrackPos=0
端函数
"触底"
公共共享函数到达底部(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.max=scrollInf.nTrackPos+scrollInf.nPage
端函数
“到达山顶
公共共享函数ReachedTop(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.nTrackPos<0
端函数
末级
#末端区域

防止RichTextbox反弹效应▲▼ 当垂直条位于底部时,您可以将下面的类粘贴到项目中,并按如下方式使用它:

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

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

这是我根据这里提供的代码修改的版本:of@King

#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
#区域“滚动条信息”
公共类ScrollBarInfo
_
私有共享函数GetScrollInfo(hwnd作为IntPtr,nBar作为整数,ByRef scrollInfo作为scrollInfo)作为整数
端函数
私有共享scrollInf作为新的SCROLLINFO
私有结构滚动信息
公共cbSize为整数
作为整数的公共fMask
公共最小值为整数
作为整数的公共最大值
作为整数的公共nPage
作为整数的公共非营利组织
公共nTrackPos为整数
端部结构
私有共享子Get_ScrollInfo(控件作为控件)
scrollInf=新的SCROLLINFO()
scrollInf.cbSize=System.Runtime.InteropServices.Marshal.SizeOf(scrollInf)
scrollInf.fMask=&H10或&H1或&H2'SIF\U范围=&H1,SIF\U页面=&H2,SIF\U轨迹位置=&H10
GetScrollInfo(control.Handle,1,scrollInf)
端接头
“我的屁股
公共共享函数IsAtBottom(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.max=(scrollInf.nTrackPos+scrollInf.nPage)-1
端函数
“伊萨托普
公共共享函数IsAtTop(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.nTrackPos=0
端函数
"触底"
公共共享函数到达底部(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.max=scrollInf.nTrackPos+scrollInf.nPage
端函数
“到达山顶
公共共享函数ReachedTop(控件作为控件)为布尔值
获取滚动信息(控件)
返回scrollInf.nTrackPos<0
端函数
末级
#末端区域

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

RichTextBox1.HideSelection = False

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

RichTextBox1.HideSelection = False

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


rtblog.AppendText(dbcon.insertdata&Chr(13))

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


rtblog.AppendText(dbcon.insertdata&Chr(13))

看一看这个:看一看这个:这并不能回答这个问题。若要评论或要求作者澄清,请在他们的帖子下方留下评论-你可以随时在自己的帖子上发表评论,一旦你有足够的评论,你就可以发表评论了。这对我很有用。新信息被附加到底部,并保持在焦点位置。这并不提供问题的答案。若要评论或要求作者澄清,请在他们的帖子下方留下评论-你可以随时在自己的帖子上发表评论,一旦你有足够的评论,你就可以发表评论了。这对我很有用。新信息将附加到底部并保持焦点