You probably shouldn't use TextWidth to change the height of the textbox but rather the TextHeight. To use TextHeight you need to know how many lines there are. Here's how to do the whole thing.
VB Code:
Option Explicit Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" _ (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam _ As Long, ByVal lParam As Long) As Long Const EM_GETLINECOUNT = 186 Private Sub Text1_Change() Dim lngLineCount As Long ' Make sure we're at the beginning Text1.SelStart = 0 ' Count the number of lines in Text1 lngLineCount = SendMessageAsLong(Text1.hWnd, EM_GETLINECOUNT, 0, 0) ' Multiply line count by line height and add 120 for border Text1.Height = TextHeight(Text1.Text) * lngLineCount + 120 ' Make sure the next character gets placed at the end Text1.SelStart = Len(Text1.Text) + 1 End Sub




Reply With Quote