vb.net 将光标移到文本框/富文本框的末尾
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19477748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
make the cursor to the end of textbox/richtextbox
提问by user2900109
I am creating auto typing application. how its work: ? Click on load text file (file will be loaded to richtextbox2) ? Click Start: (Timer will start to type the code on richtextbox1 from richtextbox2) ? But here I get stuck with problem:
我正在创建自动打字应用程序。它是如何工作的:?单击加载文本文件(文件将加载到richtextbox2)?点击开始:(定时器将从richtextbox2开始在richtextbox1上键入代码)?但在这里我遇到了问题:
(I used the following code already but don't work for me) used code:
(我已经使用了以下代码,但对我不起作用)使用的代码:
RichTextBox1.SelectionStart = RichTextBox1.TextLength
RichTextBox1.ScrollToCaret()
But Timer Value is 100 and it works with the count_ code: So the Scrollbar Continuously Go ▲▼▲▼▲▼ (up, down, up down, ...) if I removed this code: Then the scrollbar doesn't go down automatically. If manually done then I get on the first line,1st word automatically if timer is in process...
但是定时器值是 100 并且它与 count_ 代码一起工作:所以滚动条连续移动▲▼▲▼▲▼(向上,向下,向上向下,...)如果我删除了这个代码:那么滚动条不会向下自动地。如果手动完成,那么如果计时器正在处理,我会自动进入第一行,第一个字...
So please Help me what Can I do
所以请帮助我我能做什么
采纳答案by ElektroStudios
To prevent the RichTextbox rebound effect ▲▼ when vertical bar it at bottom you can paste the Class below into your project and use it like in this:
为了防止 RichTextbox 在底部竖线时出现反弹效果▲▼,您可以将下面的类粘贴到您的项目中并像这样使用它:
RichTextBox1.Select(RichTextBox1.TextLength - 1, 1)
If Not ScrollBarInfo.IsAtBottom(RichTextBox1) Then
RichTextBox1.ScrollToCaret()
End If
This is my modified version from code provided here: How to know if RichTextBox vertical Scrollbar reached the max value?of @King King
这是我从此处提供的代码修改后的版本:如何知道 RichTextBox 垂直滚动条是否达到最大值?的@King 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
回答by user3827507
Add the following to you code
将以下代码添加到您的代码中
RichTextBox1.HideSelection = False
回答by Andrea Savojardo
When you set the RichTextBox's "Hide Selection" Property to Falsein the designer, AND usethe "AppendText" method, the RichTextBox will automatically scroll down to the bottom line when it is appended.
当您在设计器中将 RichTextBox 的“隐藏选择”属性设置为False,并使用“ AppendText”方法时,RichTextBox 将在附加时自动向下滚动到底线。
rtblog.AppendText(dbcon.insertdata & Chr(13))
博客。AppendText(dbcon.insertdata & Chr(13))

