TheVampire
Programmer
I found this elsewhere, but's it's so neat I thought I'd pass it along.
With just a few API calls, you can set a control to be sizeable by the user while the program is running. The control has to have a windows handle, so there are a few controls that this will not work for. ( like labels and image boxes )
First, you need these API calls and constants in your declarations section:
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 Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)
Private Const WS_THICKFRAME = &H40000
Private Const WS_EX_STATICEDGE = &H20000
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
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOSIZE = &H1
Next, you perform these operations on the control.
SetWindowLong Control.hwnd, GWL_STYLE, GetWindowLong(Control.hwnd, GWL_STYLE) Or WS_THICKFRAME
SetWindowLong Control.hwnd, GWL_EXSTYLE, GetWindowLong(Control.hwnd, GWL_EXSTYLE) Or WS_EX_STATICEDGE
SetWindowPos Control.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED
And that's it! Now, when you move your mouse to the border of the control, you will get a sizeing arrow. ( Sorry, I don't know how to make the "Grab Handles" )
If you left click and drag, you can make the control resize!
Different controls act different ways to this. List boxes will automatically show or hide scroll bars as necessary. Combos will not size up or down, but will size left and right.
One of the most useful controls that I found to use with this method is the picturebox. With two ( or more ) pictureboxes set up like this, you can put other controls inside of them and resize them inside the picturebox resize event. This way you can set up a "Splitter", by resizeing one picturebox using the mouse, you can then set the other one's size in code. Like windows explorer and a lot of other programs.
Hope this helps someone else out there!
Robert
With just a few API calls, you can set a control to be sizeable by the user while the program is running. The control has to have a windows handle, so there are a few controls that this will not work for. ( like labels and image boxes )
First, you need these API calls and constants in your declarations section:
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 Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)
Private Const WS_THICKFRAME = &H40000
Private Const WS_EX_STATICEDGE = &H20000
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
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOSIZE = &H1
Next, you perform these operations on the control.
SetWindowLong Control.hwnd, GWL_STYLE, GetWindowLong(Control.hwnd, GWL_STYLE) Or WS_THICKFRAME
SetWindowLong Control.hwnd, GWL_EXSTYLE, GetWindowLong(Control.hwnd, GWL_EXSTYLE) Or WS_EX_STATICEDGE
SetWindowPos Control.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED
And that's it! Now, when you move your mouse to the border of the control, you will get a sizeing arrow. ( Sorry, I don't know how to make the "Grab Handles" )
If you left click and drag, you can make the control resize!
Different controls act different ways to this. List boxes will automatically show or hide scroll bars as necessary. Combos will not size up or down, but will size left and right.
One of the most useful controls that I found to use with this method is the picturebox. With two ( or more ) pictureboxes set up like this, you can put other controls inside of them and resize them inside the picturebox resize event. This way you can set up a "Splitter", by resizeing one picturebox using the mouse, you can then set the other one's size in code. Like windows explorer and a lot of other programs.
Hope this helps someone else out there!
Robert