Hey,
I'm wondering how to scroll smoothly down a RTB using a timer. By smooth im not meaning one line at a time, but more a few pixels.
How do I do this?
Thanks,
Jessee
Printable View
Hey,
I'm wondering how to scroll smoothly down a RTB using a timer. By smooth im not meaning one line at a time, but more a few pixels.
How do I do this?
Thanks,
Jessee
resize your rtb so it shows all of the text, set scrollbars = none, then paste it onto a panel. set the panel autoscroll property to true, then:
vb Code:
''' <summary> ''' timer ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks>interval = 100ms</remarks> Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X, Math.Abs(Panel1.AutoScrollPosition.Y) + 1) End Sub
Hey,
That works but since the text in the rich text box changes length, I cant have a fixed size textbox.
Which means I have a huge textbox, and the scroll bar on the panel is huge.
Is there an easier way?
Thanks!
Jessee
ok here's an alternative method without the panel. it uses the windows API function sendmessage:
vb Code:
Public Class Form1 Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByRef lParam As POINT) As Integer Const EM_GETSCROLLPOS As Integer = 1245 Const EM_SETSCROLLPOS As Integer = 1246 Structure POINT Dim x As Integer Dim y As Integer End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim p As New POINT SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, 0, p) p.y += 1 SendMessage(RichTextBox1.Handle, EM_SETSCROLLPOS, 0, p) End Sub End Class