Make A Resizeable Text Box

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 Text Box and 2 Command Buttons to your form.
'Insert this code to the module :

Public Const SWP_DRAWFRAME = &H20
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_FLAGS = SWP_NOZORDER Or SWP_NOSIZE Or _
SWP_NOMOVE Or SWP_DRAWFRAME
Public Const GWL_STYLE = (-16)
Public Const WS_THICKFRAME = &H40000
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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

'Insert the following code to your form:

Dim initBoxStyle As Long

Private Sub Command2_Click()
SetControlStyle initBoxStyle, Text1
End Sub

Private Sub Form_Load()
Command1.Caption = "Start Resizing"
Command2.Caption = "Complete Resizing"
initBoxStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
SetControlStyle initBoxStyle, Text1
End Sub

Private Sub Form_Unload(Cancel As Integer)
SetControlStyle initBoxStyle, Text1
End Sub

Private Sub Command1_Click()
Dim style As Long
style = GetWindowLong(Text1.hwnd, GWL_STYLE)
style = style Or WS_THICKFRAME
SetControlStyle style, Text1
End Sub

Private Sub SetControlStyle(style, X As Control)
Dim r
If style Then
Call SetWindowLong(X.hwnd, GWL_STYLE, style)
Call SetWindowPos(X.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
End If
End Sub

Go Back