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
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
