|
-
Oct 3rd, 2010, 10:52 PM
#1
Thread Starter
Addicted Member
Smooth scrolling rich text box with timer
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
-
Oct 3rd, 2010, 11:26 PM
#2
Re: Smooth scrolling rich text box with timer
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2010, 12:35 AM
#3
Thread Starter
Addicted Member
Re: Smooth scrolling rich text box with timer
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
-
Oct 4th, 2010, 10:23 AM
#4
Re: Smooth scrolling rich text box with timer
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|