2013-10-20 115 views
1

我正在創建自動打字應用程序。 如何工作:•點擊加載文本文件(文件將被載入到richtextbox2) •點擊開始:(定時器將開始鍵入從richtextbox2 richtextbox1代碼) •不過在這裏我卡住與問題:將光標移動到文本框末尾/ richtextbox

(我用下面的代碼已經,但不爲我工作) 使用代碼:

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

但定時器的值是100,它與將count_visits代碼工作: 所以滾動條不斷進入▲▼▲▼ ▲▼(上,下,上,下),如果我刪除了這段代碼: 然後滾動條不下降自動。 如果手工完成,然後我得到的第一行,第一個字,如果自動定時器流程...

,請幫助我,我可以做

+0

看看這個: http://stackoverflow.com/questions/7518876/disable-scrolling-when-selecting-text-in -richtextbox-c – Jerry

回答

1

爲了防止RichTextBox的反彈效應▲▼時豎線它在底部,你可以粘貼Class下到項目,並用它就像這個:

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

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

這是我從代碼修改後的版本在這裏提供:How to know if RichTextBox vertical Scrollbar reached the max value?的@景景

#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

以下內容添加到您的代碼

RichTextBox1.HideSelection = False 
+0

這不提供問題的答案。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你會能夠[評論任何帖子](http://stackoverflow.com/help/privileges/comment)。 – bytecode77

+0

它適合我。新信息附加到底部並保持焦點 – user3827507

1

當您設置RichTextBox中的 「隱藏選區」 物業在設計,和使用的「AppendText通過 「方法,RichTextBox將在追加時自動向下滾動到底線。

rtblog。 AppendText通過(dbcon.insertdata & CHR(13))

相關問題