Horizontal Scrollbars

The way I work around this is to set the with of the rect (EM_SETRECT) to my desired width when the form loads. I don’t use the scroll bars property in the textbox. Instead, I place a horizontal scrollbar control below my textbox. I create my own sub that scrolls the text left and right by moving the rect (not changing size). I monitor the KeyUp and MouseUp events using the GetCaretPos function: I call the sub when required or if the scrollbar is changed.

Sub Form1_load (...etc...) 
Dim rtn&
Dim Posn As Rect
   rtn& = SendMessage(Text1.hWnd, EM_GETRECT, 0, Posn)
   'get original rect
   Posn.right = NewWidth%
   'formatting width you require
   rtn& = SendMessage(Text1.hWnd, EM_SETRECT, 0, Posn)
   'set new rect width
End Sub
Sub ScrollRect (ByVal hWnd%, direction%) 
Dim rtn&
Dim Posn As Rect
   rtn& = Send Message (hWnd%, EM_GETRECT, 0, Posn)
   'get current rect
   'to move rect left direction% is a negative number
   'to move rect right direction% is a positive number
   Posn.left = Posn.left + direction%
   Posn.right = Posn.right + direction%
   rtn& = SendMessage(hWnd%, EM_SETRECT, 0, Posn)
   'move rect left or right
End Sub


Tip By: Douglas Marquardt


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s