Results 1 to 8 of 8

Thread: Scrolling a RichTextBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Location
    Ohio
    Posts
    23

    Unhappy Scrolling a RichTextBox

    Ok, here's my problem. I have a RighTextBox, and I want my program to be able to automatically scroll the Horozontal scrollbar all the way back to the left. I tryed using the SendMessage API with the EM_SCROLL message, but I can't seem to get it to work. Any ideas?
    Jason O

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    a quick "cheat" would be something like:

    richtextbox1.selstart = 0

    if that helps ...

  3. #3
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Scrolling a RichTextBox

    Originally posted by Jdo300
    Ok, here's my problem. I have a RighTextBox, and I want my program to be able to automatically scroll the Horozontal scrollbar all the way back to the left. I tryed using the SendMessage API with the EM_SCROLL message, but I can't seem to get it to work. Any ideas?
    EM_Scroll would not help.

    use these constants ..

    VB Code:
    1. Private Const SB_LINEDOWN As Long = 1
    2. Private Const SB_LINEUP As Long = 0
    3. Private Const SB_PAGEDOWN As Long = 3
    4. Private Const SB_PAGEUP As Long = 2
    5. Private Const WM_HSCROLL = &H114
    6. Private Const WM_VSCROLL = &H115
    7.  
    8. 'examples :
    9.  
    10.  intRet = SendMessage(richtextbox1.hwnd, _
    11.                     WM_HSCROLL, _
    12.                     SB_LINEUP, 0)
    13. 'and
    14.  
    15.  intRet = SendMessage(richtextbox1.hwnd, _
    16.                     WM_VSCROLL, _
    17.                     SB_PAGEUP, 0)

    'And your rtb will scroll like hell ..

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Location
    Ohio
    Posts
    23
    Ohhh ok. sure that sounds good, but a couple of problems there:

    1. I need to scroll ONLY the horozontal scrollbar all the way to the left

    2. the textbox would have a highlighted block of text in it, so I couldn't change anything with the SelStart,len,text properties.

    3. I also looked up the EM_GETSCROLLPOS & EM_SETSCROLLPOS properties since the textbox i'm using is a RichTextBox, but I wrote a function like:

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_USER As Long = &H400
    Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
    Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
    
    Private Type POINTAPI
        x As Long
        Y As Long
    End Type
    
    'Moves the Horozontal scrollbar in txtWindow all the way to the left
    Public Function MoveScrollBar(RTB As RichTextBox)
        Dim PointX As POINTAPI 'X,Y struct containing the scroll position of the RichTextBox
        'Fill the PointX structure so the current Y position can be retrieved
        SendMessage RTB.hwnd, EM_GETSCROLLPOS, 0, PointX
        'Set the X to zero
        PointX.x = 0
        'Update the scrollbar position
        SendMessage RTB.hwnd, EM_SETSCROLLPOS, 0, PointX
        RTB.Refresh
    End Function
    and of course, it didn't work! I need help
    Jason O

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    it won't work because a richtextbox is not a textbox... amd EM_ messages are only for TEXTboxes.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by BuggyProgrammer
    it won't work because a richtextbox is not a textbox... amd EM_ messages are only for TEXTboxes.
    That's not true at all. Most EM_xxxx messages will work for both rich and regular edit boxes.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Try this...
    VB Code:
    1. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    2.                                                                             ByVal wMsg As Long, _
    3.                                                                             ByVal wParam As Long, _
    4.                                                                             ByVal lParam As Long) _
    5.                                                                             As Long
    6.  
    7. Private Const WM_HSCROLL = &H114
    8. Private Const SB_LEFT = 6
    9.  
    10. Private Const SCROLL_AMT = 100& 'Increase as necessary
    11.  
    12. Public Function MakeDWord(LoWord As Long, HiWord As Long) As Long
    13.     MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    14. End Function
    15.  
    16. 'usage
    17. Call SendMessageLong(RichTextBox1.hwnd, WM_HSCROLL, MakeDWord(SB_LEFT, SCROLL_AMT), 0&)
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Location
    Ohio
    Posts
    23
    Thanks! It works great! But I have yet another problem! The reason I needed the horizontal scrollbar to automatically go left is because I've made some code that can block tab text, and I didn't want the box to scroll right when the text is tabbed. Now, the code you gave me works fine, but the whole box blinks whenever the scrollbar is adjusted. Is there a way to simply keep the textbox from scrolling right when the text is tabbed?
    Jason O

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