Hi
I want to resize a control on a form at run time, is there any API or any idea?
thanks
MMAlwan
Visual Basic Classic
Last Comment
mmalwan
8/22/2022 - Mon
Belfry
Yes, you can use windows API MoveWindow()
first you declare it as private or public,e.g:
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
then use it in Form_Resize(), following is a sample
Private Sub Form_Resize()
'set scalemode to pixels so that it fits the API's scale mode
Me.ScaleMode = vbPixels
'center the command button
MoveWindow Command1.hwnd, Me.ScaleWidth / 2 - Command1.Width / 2, _
Me.ScaleHeight / 2 - Command1.Height / 2, _
Command1.Width, _
Command1.Height, _
True
End Sub
When you resize a form, an events form_resize() is called. You can then use the form dimension as refernce and modify the height, width (top, left) of your control in this event.
mmalwan
ASKER
hi
i don't mean that, what i mean is resizing a control like at disign mode (changing its width and height using the mouse)
MMAlwan
thanks all
xThorx I want some thing like when u ar in vbasic IDE and u want to resize the project browser for exemple, so when u are on the edge of the control the mouse pointer became a double arrow and a thin line move if u press on the left button of ur mouse.
In the mouseup event, you have to change the pointer. To have a thine line, you have to draw it and to make it visible when you have the mouse down button and delete it when you have button 1 realesed.
mmalwan
ASKER
thanks all
u may have to add something like a thin picture box to be like in vb
MMAlwan
first you declare it as private or public,e.g:
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
then use it in Form_Resize(), following is a sample
Private Sub Form_Resize()
'set scalemode to pixels so that it fits the API's scale mode
Me.ScaleMode = vbPixels
'center the command button
MoveWindow Command1.hwnd, Me.ScaleWidth / 2 - Command1.Width / 2, _
Me.ScaleHeight / 2 - Command1.Height / 2, _
Command1.Width, _
Command1.Height, _
True
End Sub
Good Luck!