Visual Basic Programming Code Examples Visual Basic > Forms Code Examples Making a textbox resizable Making a textbox resizable The following routine demonstrates how to make a textbox resizable. Option Explicit Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long 'Purpose : Make a textbox resizable 'Inputs : tbResize The textbox to make resizeable. ' [bStopResize] Set to True to stop the textbox resizing. 'Outputs : Returns the original style bit for the textbox Function TextBoxMakeSizeable(tbResize As TextBox, Optional bStopResize As Boolean = False) As Long Dim ltxtNewStyle As Long Const SWP_DRAWFRAME As Long = &H20, SWP_NOMOVE As Long = &H2 Const SWP_NOSIZE As Long = &H1, SWP_NOZORDER As Long = &H4 Const SWP_FLAGS As Long = SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME Const GWL_STYLE As Long = (-16) Const WS_THICKFRAME As Long = &H40000 'Get the current textbox style TextBoxMakeSizeable = GetWindowLong(tbResize.hwnd, GWL_STYLE) If bStopResize Then 'Modify the style bit to show a sizing frame ltxtNewStyle = TextBoxMakeSizeable And Not WS_THICKFRAME Else 'Modify the style bit to show a sizing frame ltxtNewStyle = TextBoxMakeSizeable Or WS_THICKFRAME End If 'Set the new textbox style and redraw the window in the new style Call SetWindowLong(tbResize.hwnd, GWL_STYLE, ltxtNewStyle) Call SetWindowPos(tbResize.hwnd, tbResize.Parent.hwnd, 0, 0, 0, 0, SWP_FLAGS) End Function 'Demonstration routine Private Sub Form_Load() TextBoxMakeSizeable Me.Text1 End Sub