RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
May 21, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Read and modify a TextBox control's formatting rectangle

By sending appropriate messages to a multi-line TextBox control you can read and modify its formatting rectangle - that is, the inner portion of the control where the user can type. Modifying the size and position of this area can be useful, for example, to leave a left margin where you can add line numbers or other text markers. Here's is the complete source code for the two routines that read and modify the formatting rectangle:

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 Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type


' Get the formatting rectangle.

Sub TextBoxGetRect(tb As TextBox, Left As Long, Top As Long, Right As Long, _
    Bottom As Long)
    Dim lpRect As RECT
    SendMessage tb.hwnd, EM_GETRECT, 0, lpRect
    Left = lpRect.Left
    Top = lpRect.Top
    Right = lpRect.Right
    Bottom = lpRect.Bottom
End Sub

' Set the formatting rectangle and refresh the control.

Sub TextBoxSetRect(tb As TextBox, ByVal Left As Long, ByVal Top As Long, _
    ByVal Right As Long, ByVal Bottom As Long)
    Dim lpRect As RECT
    lpRect.Left = Left
    lpRect.Top = Top
    lpRect.Right = Right
    lpRect.Bottom = Bottom
    SendMessage tb.hwnd, EM_SETRECT, 0, lpRect
End Sub
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date