How to Make a Text Box Resizeable
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 'Controls - How to Make a Text Box Resizeable Option Explicit 'Add a Text Box and two Command Buttons to your form. 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 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) 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 |