Ensure that a TextBox caret is visible

Setting a multiline TextBox’s SelStart property doesn’t ensure that the insertion point (the caret) is visible. You can achieve this by sending the control an appropriate message:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _    hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _    lParam As Any) As LongConst EM_SCROLLCARET = &HB7' Ensures that the caret is visible.Sub ScrollCaret(tb As TextBox)    SendMessage tb.hwnd, EM_SCROLLCARET, 0, ByVal 0&End Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: