Results 1 to 4 of 4

Thread: Smooth scrolling rich text box with timer

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    New Zealand
    Posts
    241

    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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    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:
    1. ''' <summary>
    2. ''' timer
    3. ''' </summary>
    4. ''' <param name="sender"></param>
    5. ''' <param name="e"></param>
    6. ''' <remarks>interval = 100ms</remarks>
    7. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    8.     Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X, Math.Abs(Panel1.AutoScrollPosition.Y) + 1)
    9. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    New Zealand
    Posts
    241

    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

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    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:
    1. Public Class Form1
    2.  
    3.     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
    4.  
    5.     Const EM_GETSCROLLPOS As Integer = 1245
    6.     Const EM_SETSCROLLPOS As Integer = 1246
    7.  
    8.     Structure POINT
    9.         Dim x As Integer
    10.         Dim y As Integer
    11.     End Structure
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Timer1.Enabled = True
    15.     End Sub
    16.  
    17.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    18.         Dim p As New POINT
    19.         SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, 0, p)
    20.         p.y += 1
    21.         SendMessage(RichTextBox1.Handle, EM_SETSCROLLPOS, 0, p)
    22.     End Sub
    23.  
    24. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width